]> git.kaiwu.me - nginx.git/commitdiff
Entity tags: explicit flag to skip not modified filter.
authorMaxim Dounin <mdounin@mdounin.ru>
Wed, 25 Jun 2014 22:27:11 +0000 (02:27 +0400)
committerMaxim Dounin <mdounin@mdounin.ru>
Wed, 25 Jun 2014 22:27:11 +0000 (02:27 +0400)
Previously, last_modified_time was tested against -1 to check if the
not modified filter should be skipped.  Notably, this prevented nginx
from additional If-Modified-Since (et al.) checks on proxied responses.
Such behaviour is suboptimal in some cases though, as checks are always
skipped on responses from a cache with ETag only (without Last-Modified),
resulting in If-None-Match being ignored in such cases.  Additionally,
it was not possible to return 412 from the If-Unmodified-Since if last
modification time was not known for some reason.

This change introduces explicit r->disable_not_modified flag instead,
which is set by ngx_http_upstream_process_headers().

src/http/modules/ngx_http_not_modified_filter_module.c
src/http/ngx_http_request.h
src/http/ngx_http_upstream.c

index 357d085fde76ac7df9e74374653a35bc5a4a9bac..acc94ded31ad8bf0a409b0b1134675f00061925c 100644 (file)
@@ -56,7 +56,7 @@ ngx_http_not_modified_header_filter(ngx_http_request_t *r)
 {
     if (r->headers_out.status != NGX_HTTP_OK
         || r != r->main
-        || r->headers_out.last_modified_time == -1)
+        || r->disable_not_modified)
     {
         return ngx_http_next_header_filter(r);
     }
@@ -114,6 +114,10 @@ ngx_http_test_if_unmodified(ngx_http_request_t *r)
 {
     time_t  iums;
 
+    if (r->headers_out.last_modified_time == (time_t) -1) {
+        return 0;
+    }
+
     iums = ngx_http_parse_time(r->headers_in.if_unmodified_since->value.data,
                                r->headers_in.if_unmodified_since->value.len);
 
@@ -134,6 +138,10 @@ ngx_http_test_if_modified(ngx_http_request_t *r)
     time_t                     ims;
     ngx_http_core_loc_conf_t  *clcf;
 
+    if (r->headers_out.last_modified_time == (time_t) -1) {
+        return 1;
+    }
+
     clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
 
     if (clcf->if_modified_since == NGX_HTTP_IMS_OFF) {
index 0d3a799159a47ca540fcbdad4b9a88d84569267b..f6ea6fb56e77c43dcf36a23b3dd6fe94abe17642 100644 (file)
@@ -528,6 +528,7 @@ struct ngx_http_request_s {
     unsigned                          filter_need_temporary:1;
     unsigned                          allow_ranges:1;
     unsigned                          single_range:1;
+    unsigned                          disable_not_modified:1;
 
 #if (NGX_STAT_STUB)
     unsigned                          stat_reading:1;
index 8922dbc8b23bf6f77862b42cc22b0c6e8b3549b3..5b55b263bd7734fe1995f16ad85986b25604b5b1 100644 (file)
@@ -2238,6 +2238,8 @@ ngx_http_upstream_process_headers(ngx_http_request_t *r, ngx_http_upstream_t *u)
 
     r->headers_out.content_length_n = u->headers_in.content_length_n;
 
+    r->disable_not_modified = !u->cacheable;
+
     u->length = -1;
 
     return NGX_OK;