internal static CacheResponseProperty LoadFrom(System.Net.Cache.RequestCachePolicy req, HttpWebResponse response)
        {
            var property = new CacheResponseProperty()
            {
                IsFromCache = response.IsFromCache,
            };

            if (response.IsFromCache)
            {
                var policy = req as System.Net.Cache.HttpRequestCachePolicy;

                property.CacheSyncDate = policy.CacheSyncDate;
                property.Level         = policy.Level;
                property.MaxAge        = policy.MaxAge;
                property.MaxStale      = policy.MaxStale;
                property.MinFresh      = policy.MinFresh;

                property.AgeInSeconds = int.Parse(response.Headers[HttpResponseHeader.Age], CultureInfo.InvariantCulture);
                property.CacheControl = response.Headers[HttpResponseHeader.CacheControl];
                property.Vary         = response.Headers[HttpResponseHeader.Vary];
                property.Via          = response.Headers[HttpResponseHeader.Via];
                property.Warning      = response.Headers[HttpResponseHeader.Warning];
            }
            return(property);
        }
示例#2
0
            static HttpResponseMessage PopulateResponse(HttpTransportAsyncResult self)
            {
                HttpResponseMessage response;

                Trace(self, "PopulateResponse");
                var webResponse = self.webResponse;

                long?len = null;

                if (webResponse.ContentLength != -1)
                {
                    len = webResponse.ContentLength;
                }
                response = new HttpResponseMessage()
                {
                    Request    = self.request,
                    Content    = HttpContent.Create(new HttpWebResponseInputStream(webResponse), webResponse.ContentType, len),
                    Uri        = webResponse.ResponseUri,
                    StatusCode = webResponse.StatusCode,
                    Method     = webResponse.Method,
                };

                if (webResponse.IsFromCache)
                {
                    response.Properties.Add(CacheResponseProperty.LoadFrom(self.webRequest.CachePolicy, webResponse));
                }

                var webResponseHeaders = webResponse.Headers;
                var responseHeaders    = response.Headers;

                CopyHeadersFromHttpWebResponse(webResponseHeaders, responseHeaders);

                if (response.Method == "HEAD")
                {
                    response.Content.LoadIntoBuffer();
                }

                var webRequestHeaders = self.webRequest.Headers;
                var requestHeaders    = self.request.Headers;

                foreach (var newHeader in webRequestHeaders.AllKeys)
                {
                    if (!requestHeaders.ContainsKey(newHeader))
                    {
                        requestHeaders.Add(newHeader, webRequestHeaders[newHeader]);
                    }
                }

                if (self.settings.Cookies != null)
                {
                    self.settings.Cookies.Add(webResponse.Cookies);
                    response.Properties.Add(new CookieCollection()
                    {
                        webResponse.Cookies
                    });
                }

                return(response);
            }
        internal static CacheResponseProperty LoadFrom(System.Net.Cache.RequestCachePolicy req, HttpWebResponse response)
        {
            var property = new CacheResponseProperty()
                {
                    IsFromCache = response.IsFromCache,
                };

            if (response.IsFromCache)
            {
                var policy = req as System.Net.Cache.HttpRequestCachePolicy;

                property.CacheSyncDate = policy.CacheSyncDate;
                property.Level = policy.Level;
                property.MaxAge = policy.MaxAge;
                property.MaxStale = policy.MaxStale;
                property.MinFresh = policy.MinFresh;

                property.AgeInSeconds = int.Parse(response.Headers[HttpResponseHeader.Age],CultureInfo.InvariantCulture);
                property.CacheControl = response.Headers[HttpResponseHeader.CacheControl];
                property.Vary = response.Headers[HttpResponseHeader.Vary];
                property.Via = response.Headers[HttpResponseHeader.Via];
                property.Warning = response.Headers[HttpResponseHeader.Warning];
            }
            return property;
        }