Head requests and chunked transfer encoding

Hi,

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?

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

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.

Hello, I applied that patch, but still the same response.

On Wed, Oct 01, 2008 at 12:32:37PM +0200, Robert G. wrote:

Hello, I applied that patch, but still the same response.

Sorry, the new patch should fix it.

Spil G. wrote:

Thanks for the quick response!

[[email protected]:~/downloads/source/nginx-0.6.32]# patch -p0 <
patch.head1
patching file src/http/modules/ngx_http_chunked_filter_module.c
Hunk #1 FAILED at 53.
1 out of 1 hunk FAILED – saving rejects to file
src/http/modules/ngx_http_chunked_filter_module.c.rej

Am i doing something wrong? Or do i have to do this with a fresh source?

Thanks for the quick response!

Spil G. wrote:

Robert G. wrote:

Am i doing something wrong? Or do i have to do this with a fresh source?

At my end it applies to Nginx 0.6.32 just fine…

Yes it needs a fresh source, the other source that I had was already
patch with the first patch :slight_smile:

OK it seem to work fine now. The patch is good :slight_smile: Thx Igor.

Robert G. wrote:

Am i doing something wrong? Or do i have to do this with a fresh source?

At my end it applies to Nginx 0.6.32 just fine…

Igor S. wrote:

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

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.

What about the other way round? I send the following:

POST / HTTP/1.0
User-Agent: Wget/1.11.3
Accept: /
Host: localhost
Connection: Keep-Alive
Content-Type: application/x-www-form-urlencoded
Transfer-Encoding: chunked
Content-Length: 142

<-- body here -->

And receive:

HTTP/1.1 411 Length Required
Server: nginx
Date: Thu, 23 Oct 2008 11:08:57 GMT
Content-Type: text/html
Content-Length: 146
Connection: close

411 Length Required

411 Length Required

I think that somebody took rfc2616 section 4.4 a little to literally:

3. ... If a message is received with both a Transfer-Encoding header field and a Content-Length header field, the latter MUST be ignored.

Content-Length MUST be ignored, but it doesn’t mean it should bail with
an error. Or am I missing something?

Hello!

On Thu, Oct 23, 2008 at 01:22:38PM +0200, Daniel Crompton wrote:

[…]

<-- body here -->

And receive:

HTTP/1.1 411 Length Required

[…]

I think that somebody took rfc2616 section 4.4 a little to literally:

3. ... If a message is received with both a Transfer-Encoding header field and a Content-Length header field, the latter MUST be ignored.

Content-Length MUST be ignored, but it doesn’t mean it should bail with
an error. Or am I missing something?

As of now nginx doesn’t support chunked encoding from client.

Maxim D.

Maxim D. wrote:

Hello!
On Thu, Oct 23, 2008 at 01:22:38PM +0200, Daniel Crompton wrote:

Content-Length MUST be ignored, but it doesn’t mean it should bail with
an error. Or am I missing something?

As of now nginx doesn’t support chunked encoding from client.

I don’t understand. Do you mean you stopped supporting it or that you
don’t support it yet?

D.

On Wed, Oct 01, 2008 at 02:02:06PM +0200, Robert G. wrote:

Am i doing something wrong? Or do i have to do this with a fresh source?
Fresh source.

Best regards,
Grzegorz N.

Hello!

On Thu, Oct 23, 2008 at 02:00:47PM +0200, Daniel Crompton wrote:

Maxim D. wrote:

Hello!
On Thu, Oct 23, 2008 at 01:22:38PM +0200, Daniel Crompton wrote:

Content-Length MUST be ignored, but it doesn’t mean it should bail with
an error. Or am I missing something?

As of now nginx doesn’t support chunked encoding from client.

I don’t understand. Do you mean you stopped supporting it or that you
don’t support it yet?

Not me, nginx.

It wasn’t ever supported. Hopefully things will change
eventually.

Maxim D.

Maxim D. wrote:

On Thu, Oct 23, 2008 at 02:00:47PM +0200, Daniel Crompton wrote:

I don’t understand. Do you mean you stopped supporting it or that you
don’t support it yet?

Not me, nginx.

It wasn’t ever supported. Hopefully things will change
eventually.

Sorry, I didn’t mean you. :slight_smile: I meant nginx.

Thanks for the answer.

D.