Esempio n. 1
0
        public static void Apply(this HttpCacheOptions options, HttpResponseMessage response)
        {
            if (response == null)
            {
                return;
            }

            response.Headers.CacheControl = new CacheControlHeaderValue();

            if (options.IsPublic || options.MaxAge.HasValue)
            {
                response.Headers.CacheControl.Public = true;
            }

            if (options.MaxAge.HasValue)
            {
                response.Headers.CacheControl.MaxAge = response.Headers.Age = options.MaxAge;
            }

            if (response.Content != null)
            {
                if (options.LastModified.HasValue && response.Content != null)
                {
                    response.Content.Headers.LastModified = options.LastModified.Value;
                }

                response.Content.Headers.Expires = Expires(response.Headers);
            }

            if (!string.IsNullOrEmpty(options.ETag))
            {
                response.Headers.ETag = new EntityTagHeaderValue(options.QuotedETag);
            }
        }
Esempio n. 2
0
        public static bool ETagMatches(this HttpCacheOptions options, HttpRequestMessage request)
        {
            if (request == null)
            {
                return(false);
            }

            return(request.Headers.IfNoneMatch.Any(x => x.Tag == options.QuotedETag));
        }
Esempio n. 3
0
        public static bool ETagMatches(this HttpCacheOptions options, HttpRequestBase request)
        {
            if (request == null)
            {
                return(false);
            }

            const string key = "if-None-Match";

            return(ETagMatches(options, request.Headers[key]));
        }
Esempio n. 4
0
        public static void Apply(this HttpCacheOptions options, HttpCachePolicyBase policy)
        {
            if (policy == null)
            {
                return;
            }

            policy.SetCacheability(options.IsPublic ? HttpCacheability.Public : HttpCacheability.Private);

            if (options.LastModified.HasValue)
            {
                policy.SetLastModified(options.LastModified.Value);
            }

            if (!string.IsNullOrEmpty(options.ETag))
            {
                policy.SetETag(options.QuotedETag);
            }

            if (options.MaxAge.HasValue)
            {
                policy.SetMaxAge(options.MaxAge.Value);
            }
        }
Esempio n. 5
0
 public static bool ETagMatches(this HttpCacheOptions options, string value)
 {
     return(options.QuotedETag == value);
 }