]> git.kaiwu.me - nginx.git/commitdiff
refactor gzip_vary handling
authorIgor Sysoev <igor@sysoev.ru>
Thu, 12 Nov 2009 13:41:56 +0000 (13:41 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Thu, 12 Nov 2009 13:41:56 +0000 (13:41 +0000)
src/http/modules/ngx_http_gzip_filter_module.c
src/http/modules/ngx_http_gzip_static_module.c
src/http/ngx_http_core_module.c
src/http/ngx_http_header_filter_module.c
src/http/ngx_http_request.h

index 62b430b7170fafaeaa9bbbc67ce6a0c9a36d7a7d..4c0c0d201f77ddc46911d1fa5ffd8d58a906f870 100644 (file)
@@ -251,12 +251,22 @@ ngx_http_gzip_header_filter(ngx_http_request_t *r)
             && r->headers_out.content_encoding->value.len)
         || (r->headers_out.content_length_n != -1
             && r->headers_out.content_length_n < conf->min_length)
-        || ngx_http_test_content_type(r, &conf->types) == NULL
-        || ngx_http_gzip_ok(r) != NGX_OK)
+        || ngx_http_test_content_type(r, &conf->types) == NULL)
     {
         return ngx_http_next_header_filter(r);
     }
 
+    r->gzip_vary = 1;
+
+    if (!r->gzip_tested) {
+        if (ngx_http_gzip_ok(r) != NGX_OK) {
+            return ngx_http_next_header_filter(r);
+        }
+
+    } else if (!r->gzip_ok) {
+        return ngx_http_next_header_filter(r);
+    }
+
     ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_gzip_ctx_t));
     if (ctx == NULL) {
         return NGX_ERROR;
index cff23e02a55a682e6a3f0bf0d536fe429244f63e..a928d16aeeaaa3264ba5d501066c38e41514496c 100644 (file)
@@ -145,7 +145,6 @@ ngx_http_gzip_static_handler(ngx_http_request_t *r)
         case NGX_ENOTDIR:
         case NGX_ENAMETOOLONG:
 
-            r->gzip = 0;
             return NGX_DECLINED;
 
         case NGX_EACCES:
@@ -165,6 +164,8 @@ ngx_http_gzip_static_handler(ngx_http_request_t *r)
         return NGX_DECLINED;
     }
 
+    r->gzip_vary = 1;
+
     if (rc != NGX_OK) {
         return NGX_DECLINED;
     }
index 9cce2d54761c430f557e43787728d02cf8a0a038..ee0864c14be83239b188ffe5ccf266d601c40c4d 100644 (file)
@@ -812,7 +812,11 @@ ngx_http_handler(ngx_http_request_t *r)
     }
 
     r->valid_location = 1;
-    r->gzip = 0;
+#if (NGX_HTTP_GZIP)
+    r->gzip_tested = 0;
+    r->gzip_ok = 0;
+    r->gzip_vary = 0;
+#endif
 
     r->write_event_handler = ngx_http_core_run_phases;
     ngx_http_core_run_phases(r);
@@ -1891,15 +1895,7 @@ ngx_http_gzip_ok(ngx_http_request_t *r)
     ngx_table_elt_t           *e, *d;
     ngx_http_core_loc_conf_t  *clcf;
 
-    if (r->gzip == 1) {
-        return NGX_OK;
-    }
-
-    if (r->gzip == 2) {
-        return NGX_DECLINED;
-    }
-
-    r->gzip = 2;
+    r->gzip_tested = 1;
 
     if (r != r->main
         || r->headers_in.accept_encoding == NULL
@@ -2034,7 +2030,7 @@ ok:
 
 #endif
 
-    r->gzip = 1;
+    r->gzip_ok = 1;
 
     return NGX_OK;
 }
index 9044c4040007f2d89881b1565e1b4f69d4d03469..0f6f1731a1cc5e7032ccd9dd35a1751aafe6531d 100644 (file)
@@ -399,8 +399,13 @@ ngx_http_header_filter(ngx_http_request_t *r)
     }
 
 #if (NGX_HTTP_GZIP)
-    if (r->gzip && clcf->gzip_vary) {
-        len += sizeof("Vary: Accept-Encoding" CRLF) - 1;
+    if (r->gzip_vary) {
+        if (clcf->gzip_vary) {
+            len += sizeof("Vary: Accept-Encoding" CRLF) - 1;
+
+        } else {
+            r->gzip_vary = 0;
+        }
     }
 #endif
 
@@ -559,7 +564,7 @@ ngx_http_header_filter(ngx_http_request_t *r)
     }
 
 #if (NGX_HTTP_GZIP)
-    if (r->gzip && clcf->gzip_vary) {
+    if (r->gzip_vary) {
         b->last = ngx_cpymem(b->last, "Vary: Accept-Encoding" CRLF,
                              sizeof("Vary: Accept-Encoding" CRLF) - 1);
     }
index 8f348154c8d442ddd84194fdd369330db74bf6b2..ade15a50a4a3d53959b31a000d09624e182d4b71 100644 (file)
@@ -457,7 +457,12 @@ struct ngx_http_request_s {
 #if (NGX_HTTP_CACHE)
     unsigned                          cached:1;
 #endif
-    unsigned                          gzip:2;
+
+#if (NGX_HTTP_GZIP)
+    unsigned                          gzip_tested:1;
+    unsigned                          gzip_ok:1;
+    unsigned                          gzip_vary:1;
+#endif
 
     unsigned                          proxy:1;
     unsigned                          bypass_cache:1;