[erlang-bugs] Possible bug in inets http:request?

Tobias Löfgren ugglan@REDACTED
Sun Sep 17 00:50:07 CEST 2006


(Posted this to erlang-questions first by mistake, sorry for crossposting.)

I'm using inets http:request to construct REST calls to a web service and
noticed some odd behaviour which boiled down to this:

When the response contains nothing, ie. complete headers, but a zero-length
body, the function hangs for some time. To try it out:

http:request("http://combubo.com/test.txt").

The call returns after ~ 15 seconds. Other servers take minutes to break the
connection.

I located this in httpc_response.erl:

whole_body(Body, Length) ->
    case size(Body) of
    N when N < Length, N > 0->
        {?MODULE, whole_body, [Body, Length]};
    N when N >= Length, Length > 0 ->
        %% Potential trailing garbage will be thrown away in
        %% format_response/1 Some servers may send a 100-continue
        %% response without the client requesting it through an
        %% expect header in this case the trailing bytes may be
        %% part of the real response message.
        {ok, Body};
    _ ->
        {?MODULE, whole_body, [Body, Length]}
    end.



and it seems this code doesn't handle the case of Length == 0, so I simply
changed it to:


case size(Body) of
    N when N < Length, N >= 0->
        {?MODULE, whole_body, [Body, Length]};
    N when N >= Length, Length >= 0 ->


which seems to work fine for me, empty body responses now return right away.

Anyone know if I might have broken anything else by this patch, am I
completely barking up the wrong tree?

/Tobias
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20060917/0c151837/attachment.htm>


More information about the erlang-bugs mailing list