From afbfc8b4513a663d90cf0728633b8430fe691030 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Mon, 1 Feb 2010 15:54:02 +0000 Subject: 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 --- src/http/modules/ngx_http_gzip_filter_module.c | 14 ++++++++++++-- src/http/modules/ngx_http_gzip_static_module.c | 3 ++- src/http/modules/ngx_http_not_modified_filter_module.c | 5 +++++ 3 files changed, 19 insertions(+), 3 deletions(-) (limited to 'src/http/modules') 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); } -- cgit