[erlang-bugs] Bug in http_request module when POSTing/PUTting Zero Length Data

Carl Meijer hammingweight@REDACTED
Wed Feb 27 10:54:17 CET 2013


If I try to POST/PUT data of zero length, the http_request
module removes the "Content-Length: 0" from the HTTP headers. This
results in servers returning a 411 response code.

The bug can be found in lines 251-258 of http_request.erl
    case Headers#http_request_h.'content-length' of
        "0" ->
           undefined;
        _ ->
           key_value_str(atom_to_list(Key),
          Headers#http_request_h.'content-length')
    end;

I'm not sure why there is a specific test for "0". Simply replacing
the above code with

   key_value_str(atom_to_list(Key),  Headers#http_request_h.'content-length')

should work.

There are legitimate cases for doing a POST or PUT with no data.

At the moment, I'm hacking around this bug by sending zero bytes as
chunked data :)



More information about the erlang-bugs mailing list