コード例 #1
0
        public Negotiator Get <TReq, TRes>(TReq requestModel) where TReq : IRequest <TRes>
        {
            var response = _delegate.Get <TReq, TRes>(requestModel);

            response.WithHeader("Cache-Control", "public, max-age=600");
            var serialized = (string)JsonConvert.SerializeObject(response.NegotiationContext.DefaultModel);
            var hashString = _hasher.ComputeHash(serialized);

            if (!string.IsNullOrEmpty(RequestETag) && hashString == RequestETag)
            {
                return(response
                       .WithModel(null)
                       .WithStatusCode(HttpStatusCode.NotModified));
            }

            return(response
                   .WithHeader("ETag", hashString));
        }