Пример #1
0
        public async Task InvokeAsync(HttpContext context)
        {
            cachingManager.Start(context);

            AppendAuthHeaders(context);

            context.Response.OnStarting(_ =>
            {
                var httpContext = (HttpContext)_;

                cachingManager.Finish(httpContext);

                if (httpContext.Response.Headers.TryGetString(HeaderNames.ETag, out var etag))
                {
                    if (!cachingOptions.StrongETag && !ETagUtils.IsWeakEtag(etag))
                    {
                        httpContext.Response.Headers[HeaderNames.ETag] = ETagUtils.ToWeakEtag(etag);
                    }
                }

                return(Task.CompletedTask);
            }, context);

            await next(context);
        }
Пример #2
0
        private static bool IsCacheable(HttpContext httpContext, string etag)
        {
            if (!HttpMethods.IsGet(httpContext.Request.Method) || httpContext.Response.StatusCode != 200)
            {
                return(false);
            }

            if (!httpContext.Request.Headers.TryGetString(HeaderNames.IfNoneMatch, out var noneMatchValue))
            {
                return(false);
            }

            return(ETagUtils.IsSameEtag(noneMatchValue, etag));
        }