[erlang-bugs] inets-4.7.16 doesn't handle HTTP 204 responses

Andrew Birkett andy@REDACTED
Thu Nov 22 00:12:34 CET 2007


Hi,

I've been writing an erlang wrapper for Amazon's S3 storage service, and 
I've found a problem with the way inets-4.7.16 (from otp_src_R11B-5) 
handles the HTTP 204 (No content) status code.  I've attached a 
suggested patch, and also included a method of reproducing the problem.

According to RFC 2616 section 4.3, a 204 response 'must not' contain an 
entity body.  Therefore the content-length header is optional and should 
be ignored regardless.

The erlang library wrongly tries to use the content-length header when 
it receives a 204 reply.  If the content-length header is not present, 
httpc_handler tries to listen for more bytes on the socket.  With a 
persistent HTTP connection, this means the application appears to hang.

Attached is a patch against inets-4.7.16 which fixes this issue.  I've 
only recently started using erlang, so I hope it's okay.  Also, here is 
a way of reproducing the problem on unix using the socat utility as a 
mock webserver.

1. Create a 'reply-204-no-content-length' script containing the following:
#!/bin/bash
sleep 1
echo -ne 'HTTP/1.1 204 No Content\r\nSomeHeader: foo\r\n\r\n'
sleep 100

2. Run socat tcp-listen:9999,reuseaddr exec:./reply-204

3. Evaluate: http:request(put, {"http://localhost:9999/", 
[{"Content-Length","1"}, {"Content-Type","text/plain"}], [], 
<<1>>},[],[{sync,true}]).

4. This will hang for 101 seconds.  The call ultimately only returns 
because socat has closed the connection.  With the patch applied, the 
call returns immediately once the HTTP reply is received.

Andrew
--
- http://www.nobugs.org -

-------------- next part --------------
A non-text attachment was scrubbed...
Name: inets-204-bug.patch
Type: text/x-patch
Size: 678 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20071121/49eea06f/attachment.bin>


More information about the erlang-bugs mailing list