System.Net.Cache.HttpRequestCacheValidator.ValidateResponse C# (CSharp) Method

ValidateResponse() protected method

This validation method is responsible to answer whether the live response is sufficient to make the final decision for caching protocol. This is useful in case of possible failure or inconsistent results received from the remote cache.

Invalid response from this method means the request was internally modified and should be retried
protected ValidateResponse ( ) : CacheValidationStatus
return CacheValidationStatus
        protected internal override CacheValidationStatus ValidateResponse() {

            if (this.Policy.Level != HttpRequestCacheLevel.CacheOrNextCacheOnly &&
                this.Policy.Level != HttpRequestCacheLevel.Default &&
                this.Policy.Level != HttpRequestCacheLevel.Revalidate)
            {
                // Those policy levels do not modify requests
                if(Logging.On)Logging.PrintInfo(Logging.RequestCache, SR.GetString(SR.net_log_cache_response_valid_based_on_policy, Policy.ToString()));
                return CacheValidationStatus.Continue;
            }

            // We will need quick access to cache controls coming with the live response
            HttpWebResponse resp = Response as HttpWebResponse;
            if (resp == null) {
                if(Logging.On)Logging.PrintWarning(Logging.RequestCache, SR.GetString(SR.net_log_cache_null_response_failure));
                return CacheValidationStatus.Continue;
            }

            FetchHeaderValues(false);
            if(Logging.On) Logging.PrintInfo(Logging.RequestCache, "StatusCode=" + ((int)resp.StatusCode).ToString(CultureInfo.InvariantCulture) + ' ' +resp.StatusCode.ToString() +
                                                      (resp.StatusCode == HttpStatusCode.PartialContent
                                                       ?", Content-Range: " + resp.Headers[HttpKnownHeaderNames.ContentRange]
                                                       :string.Empty)
                                                      );


            // Apply our best knowledge of HTTP caching and return the result
            // that can be hooked up and revised by the upper level
            return Rfc2616.OnValidateResponse(this);
        }