Welcome! Log In Create A New Profile

Advanced

[PATCH] Not Modified: prefer entity tags over date validators

Piotr Sikora
November 18, 2014 08:18PM
# HG changeset patch
# User Piotr Sikora <piotr@cloudflare.com>
# Date 1416359232 28800
# Tue Nov 18 17:07:12 2014 -0800
# Node ID 3efade6bb02f7962a5120e1a1f95a1dc8f0b6a4c
# Parent 2f7e557eab5b501ba71418febd3de9ef1c0ab4f1
Not Modified: prefer entity tags over date validators.

RFC7232 says:

A recipient MUST ignore If-Modified-Since if the request contains an
If-None-Match header field; the condition in If-None-Match is
considered to be a more accurate replacement for the condition in
If-Modified-Since, and the two are only combined for the sake of
interoperating with older intermediaries that might not implement
If-None-Match.

and:

A recipient MUST ignore If-Unmodified-Since if the request contains
an If-Match header field; the condition in If-Match is considered to
be a more accurate replacement for the condition in
If-Unmodified-Since, and the two are only combined for the sake of
interoperating with older intermediaries that might not implement
If-Match.

Signed-off-by: Piotr Sikora <piotr@cloudflare.com>

diff -r 2f7e557eab5b -r 3efade6bb02f src/http/modules/ngx_http_not_modified_filter_module.c
--- a/src/http/modules/ngx_http_not_modified_filter_module.c Tue Nov 18 20:41:12 2014 +0300
+++ b/src/http/modules/ngx_http_not_modified_filter_module.c Tue Nov 18 17:07:12 2014 -0800
@@ -61,48 +61,47 @@ ngx_http_not_modified_header_filter(ngx_
return ngx_http_next_header_filter(r);
}

- if (r->headers_in.if_unmodified_since
- && !ngx_http_test_if_unmodified(r))
- {
- return ngx_http_filter_finalize_request(r, NULL,
- NGX_HTTP_PRECONDITION_FAILED);
+ if (r->headers_in.if_match) {
+
+ if (!ngx_http_test_if_match(r, r->headers_in.if_match, 0)) {
+ return ngx_http_filter_finalize_request(r, NULL,
+ NGX_HTTP_PRECONDITION_FAILED);
+ }
+
+ } else if (r->headers_in.if_unmodified_since) {
+
+ if (!ngx_http_test_if_unmodified(r)) {
+ return ngx_http_filter_finalize_request(r, NULL,
+ NGX_HTTP_PRECONDITION_FAILED);
+ }
}

- if (r->headers_in.if_match
- && !ngx_http_test_if_match(r, r->headers_in.if_match, 0))
- {
- return ngx_http_filter_finalize_request(r, NULL,
- NGX_HTTP_PRECONDITION_FAILED);
+ if (r->headers_in.if_none_match) {
+
+ if (ngx_http_test_if_match(r, r->headers_in.if_none_match, 1)) {
+ goto not_modified;
+ }
+
+ } else if (r->headers_in.if_modified_since) {
+
+ if (!ngx_http_test_if_modified(r)) {
+ goto not_modified;
+ }
}

- if (r->headers_in.if_modified_since || r->headers_in.if_none_match) {
+ return ngx_http_next_header_filter(r);

- if (r->headers_in.if_modified_since
- && ngx_http_test_if_modified(r))
- {
- return ngx_http_next_header_filter(r);
- }
+not_modified:

- if (r->headers_in.if_none_match
- && !ngx_http_test_if_match(r, r->headers_in.if_none_match, 1))
- {
- return ngx_http_next_header_filter(r);
- }
+ r->headers_out.status = NGX_HTTP_NOT_MODIFIED;
+ r->headers_out.status_line.len = 0;
+ r->headers_out.content_type.len = 0;
+ ngx_http_clear_content_length(r);
+ ngx_http_clear_accept_ranges(r);

- /* not modified */
-
- r->headers_out.status = NGX_HTTP_NOT_MODIFIED;
- r->headers_out.status_line.len = 0;
- r->headers_out.content_type.len = 0;
- ngx_http_clear_content_length(r);
- ngx_http_clear_accept_ranges(r);
-
- if (r->headers_out.content_encoding) {
- r->headers_out.content_encoding->hash = 0;
- r->headers_out.content_encoding = NULL;
- }
-
- return ngx_http_next_header_filter(r);
+ if (r->headers_out.content_encoding) {
+ r->headers_out.content_encoding->hash = 0;
+ r->headers_out.content_encoding = NULL;
}

return ngx_http_next_header_filter(r);

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH] Not Modified: prefer entity tags over date validators

Piotr Sikora 561 November 18, 2014 08:18PM

Re: [PATCH] Not Modified: prefer entity tags over date validators

Maxim Dounin 250 November 19, 2014 11:36AM

Re: [PATCH] Not Modified: prefer entity tags over date validators

Piotr Sikora 260 November 19, 2014 03:52PM

Re: [PATCH] Not Modified: prefer entity tags over date validators

Maxim Dounin 280 November 20, 2014 11:04AM

Re: [PATCH] Not Modified: prefer entity tags over date validators

Piotr Sikora 275 November 23, 2014 06:42AM

Re: [PATCH] Not Modified: prefer entity tags over date validators

Maxim Dounin 253 November 24, 2014 10:30AM

Re: [PATCH] Not Modified: prefer entity tags over date validators

Piotr Sikora 257 November 24, 2014 04:58PM

Re: [PATCH] Not Modified: prefer entity tags over date validators

Maxim Dounin 248 November 25, 2014 08:52AM

Re: [PATCH] Not Modified: prefer entity tags over date validators

Piotr Sikora 243 November 25, 2014 07:58PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 269
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready