summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2010-02-01 15:54:02 +0000
committerIgor Sysoev <igor@sysoev.ru>2010-02-01 15:54:02 +0000
commitafbfc8b4513a663d90cf0728633b8430fe691030 (patch)
treed649f3222e846e2afb731112651da8427fd7cfc7
parentc419414db440c298006d814936de28964d654b38 (diff)
downloadnginx-afbfc8b4513a663d90cf0728633b8430fe691030.tar.gz
nginx-afbfc8b4513a663d90cf0728633b8430fe691030.tar.bz2
merge r3309, r3314, r3315, r3380:
gzip headers related fixes: *) remove "Content-Encoding: gzip" in 304 response sent by ngx_http_gzip_static_module *) refactor gzip_vary handling *) test r->header_only last, since it's not actually frequent here: 304 and HEAD responses are not set it before the filter
-rw-r--r--src/http/modules/ngx_http_gzip_filter_module.c14
-rw-r--r--src/http/modules/ngx_http_gzip_static_module.c3
-rw-r--r--src/http/modules/ngx_http_not_modified_filter_module.c5
-rw-r--r--src/http/ngx_http_core_module.c18
-rw-r--r--src/http/ngx_http_header_filter_module.c11
-rw-r--r--src/http/ngx_http_request.h7
6 files changed, 40 insertions, 18 deletions
diff --git a/src/http/modules/ngx_http_gzip_filter_module.c b/src/http/modules/ngx_http_gzip_filter_module.c
index 62b430b71..2c67a36f1 100644
--- a/src/http/modules/ngx_http_gzip_filter_module.c
+++ b/src/http/modules/ngx_http_gzip_filter_module.c
@@ -246,17 +246,27 @@ ngx_http_gzip_header_filter(ngx_http_request_t *r)
|| (r->headers_out.status != NGX_HTTP_OK
&& r->headers_out.status != NGX_HTTP_FORBIDDEN
&& r->headers_out.status != NGX_HTTP_NOT_FOUND)
- || r->header_only
|| (r->headers_out.content_encoding
&& 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)
+ || r->header_only)
{
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;
diff --git a/src/http/modules/ngx_http_gzip_static_module.c b/src/http/modules/ngx_http_gzip_static_module.c
index 45ab6aaa2..29874a33a 100644
--- a/src/http/modules/ngx_http_gzip_static_module.c
+++ b/src/http/modules/ngx_http_gzip_static_module.c
@@ -144,7 +144,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:
@@ -164,6 +163,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;
}
diff --git a/src/http/modules/ngx_http_not_modified_filter_module.c b/src/http/modules/ngx_http_not_modified_filter_module.c
index 5312b3a22..705815740 100644
--- a/src/http/modules/ngx_http_not_modified_filter_module.c
+++ b/src/http/modules/ngx_http_not_modified_filter_module.c
@@ -88,6 +88,11 @@ ngx_http_not_modified_header_filter(ngx_http_request_t *r)
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);
}
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 6159e9213..7bb3ad25c 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -773,7 +773,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);
@@ -1860,15 +1864,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
@@ -2003,7 +1999,7 @@ ok:
#endif
- r->gzip = 1;
+ r->gzip_ok = 1;
return NGX_OK;
}
diff --git a/src/http/ngx_http_header_filter_module.c b/src/http/ngx_http_header_filter_module.c
index 9044c4040..0f6f1731a 100644
--- a/src/http/ngx_http_header_filter_module.c
+++ b/src/http/ngx_http_header_filter_module.c
@@ -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);
}
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index 78dabddbd..974020ef8 100644
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -451,7 +451,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;