Exemple #1
0
 /// <summary>
 /// This method will either add or update the necessary HTTP response headers needed to provide entity tag header information.
 /// </summary>
 /// <param name="response">The <see cref="HttpResponse"/> to extend.</param>
 /// <param name="request">An instance of the <see cref="HttpRequest"/> object.</param>
 /// <param name="builder">A <see cref="ChecksumBuilder"/> that represents the integrity of the client.</param>
 /// <param name="isWeak">A value that indicates if this entity-tag header is a weak validator.</param>
 public static void SetEntityTagHeaderInformation(this HttpResponse response, HttpRequest request, ChecksumBuilder builder, bool isWeak = false)
 {
     Validator.ThrowIfNull(response, nameof(response));
     Validator.ThrowIfNull(request, nameof(request));
     Validator.ThrowIfNull(builder, nameof(builder));
     builder = builder.CombineWith(request.Headers[HeaderNames.Accept]);
     if (response.IsSuccessStatusCode() && request.IsClientSideResourceCached(builder))
     {
         response.StatusCode = StatusCodes.Status304NotModified;
     }
     response.Headers.AddOrUpdate(HeaderNames.ETag, new StringValues(builder.ToEntityTag(isWeak).ToString()));
 }
        /// <summary>
        /// This method will either add or update the necessary HTTP response headers needed to provide entity tag header information.
        /// </summary>
        /// <param name="response">The <see cref="HttpResponse"/> to extend.</param>
        /// <param name="request">An instance of the <see cref="HttpRequest"/> object.</param>
        /// <param name="builder">A <see cref="ChecksumBuilder"/> that represents the integrity of the client.</param>
        /// <param name="isWeak">A value that indicates if this entity-tag header is a weak validator.</param>
        public static void SetEntityTagHeaderInformation(this HttpResponse response, HttpRequest request, ChecksumBuilder builder, bool isWeak = false)
        {
            Validator.ThrowIfNull(response, nameof(response));
            Validator.ThrowIfNull(request, nameof(request));
            Validator.ThrowIfNull(builder, nameof(builder));
            builder = builder.CombineWith(request.Headers["Accept"]);
            DateTime utcNow = DateTime.UtcNow;

            if (request.IsClientSideResourceCached(builder))
            {
                response.StatusCode = StatusCodes.Status304NotModified;
            }
            else
            {
                response.Headers.AddOrUpdate(HeaderNames.LastModified, new StringValues(utcNow.ToString("R", DateTimeFormatInfo.InvariantInfo)));
            }
            response.Headers.AddOrUpdate(HeaderNames.ETag, new StringValues(builder.ToEntityTag(isWeak).ToString()));
        }