head requests and chunked transfer encoding

Igor Sysoev is at rambler-co.ru
Wed Oct 1 13:19:34 MSD 2008


On Wed, Oct 01, 2008 at 11:05:19AM +0200, Spil Games wrote:

> I ran into some problems with Curl doing HEAD requests on an Nginx
> server:
> 
> $ curl -I 'http://www.mydomain.com/test.php'
> HTTP/1.1 200 OK
> Server: nginx
> Date: Wed, 01 Oct 2008 09:01:16 GMT
> Content-Type: text/html
> Transfer-Encoding: chunked
> Connection: keep-alive
> 
> curl: (18) transfer closed with outstanding read data remaining
> 
> 
> I think the problem occurs under the following circumstances:
> 
> - 'Content-Length' header not set (by PHP)
> - 'Transfer-Encoding: chunked' header set (by Nginx)
> 
> 
> And I believe Nginx may be at fault because I believe it should send at
> least one empty chunk when claimed to do chunked transfer encoding.
> 
> Wouldn't it be better to not use chunked transfer encoding at all for
> HEAD requests?

Yes, nginx should not set the "Transfer-Encoding: chunked".
The attached patch fixes this.


-- 
Igor Sysoev
http://sysoev.ru/en/
-------------- next part --------------
Index: src/http/modules/ngx_http_chunked_filter_module.c
===================================================================
--- src/http/modules/ngx_http_chunked_filter_module.c	(revision 1588)
+++ src/http/modules/ngx_http_chunked_filter_module.c	(working copy)
@@ -53,7 +53,8 @@
     if (r->headers_out.status == NGX_HTTP_NOT_MODIFIED
         || r->headers_out.status == NGX_HTTP_NO_CONTENT
         || r->headers_out.status == NGX_HTTP_CREATED
-        || r != r->main)
+        || r != r->main
+        || r->header_only)
     {
         return ngx_http_next_header_filter(r);
     }


More information about the nginx mailing list