#261 closed defect (fixed)
HEAD requests still have content-type when gzip on
Reported by: | Stephen Dendtler | Owned by: | Valentin V. Bartenev |
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | nginx-module | Version: | 1.3.x |
Keywords: | gzip | Cc: | |
uname -a: | Linux - 2.6.32-71.el6.x86_64 #1 SMP Fri May 20 03:51:51 BST 2011 x86_64 x86_64 x86_64 GNU/Linux | ||
nginx -V: |
nginx version: nginx/1.3.9
TLS SNI support enabled configure arguments: --prefix=/usr/local/PACKAGES/nginx-1.3.9 --with-poll_module --with-http_ssl_module --with-http_flv_module --with-openssl=/usr/local/PKG_BUILD/openssl-0.9.8r --with-pcre=/usr/local/PKG_BUILD/pcre-8.12 --add-module=nginx_uploadprogress_module --with-syslog --add-module=ngx_cache_purge-1.3 --with-file-aio --with-ld-opt=-ldl --add-module=nginx-sticky-module-1.1 |
Description
When using proxy_pass for HEAD requests, combined with gzip being turned on, nginx is returning body content even when the backend returns no content. This is a bug as no content is supposed to be returned in a HEAD response.
We're consistently seeing 20 bytes of binary data being sent after the HEAD response headers in a separate packet, possibly corresponding to a gzip header for 0 bytes of content.
This seems to be confusing some proxies such as Apache when keepalives are enabled where it sends a HEAD request followed by a GET request. Apache is accepting the content returned on the HEAD request without applying un-gzip methods, and prepending it to the content returned by the GET request as it's part of the same TCP stream. While this is arguably a problem in Apache, if nginx's output conformed to the HTTP spec then this wouldn't be an issue.
Temporary workaround is to add this to the corresponding location definition:
if ($request_method = HEAD ) {
gzip off;
}
Sample gzip config:
gzip on;
gzip_min_length 1000;
gzip_buffers 12 32k;
gzip_http_version 1.0;
gzip_comp_level 6;
gzip_proxied any;
gzip_vary off;
gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_disable "MSIE [1-6].(?!.*SV1)";
Sample request to replicate the issue:
HEAD / HTTP/1.1
Host: www.example.com
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
Headers from the upstream server will be returned (expected), along with 20 bytes of binary data (bug).
Change History (6)
comment:1 by , 12 years ago
Status: | new → accepted |
---|
comment:2 by , 12 years ago
comment:3 by , 12 years ago
Owner: | set to |
---|---|
Status: | accepted → assigned |
comment:4 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
In 4991/nginx:
(The changeset message doesn't reference this ticket)
This patch should fix the problem:
src/http/modules/ngx_http_gzip_filter_module.c