<br>I'm using inets http:request to construct REST calls to a web service and noticed some odd behaviour which boiled down to this: <br><br>When the response contains nothing, ie. complete headers, but a zero-length body, the function hangs for some time. To try it out:
<br><br>http:request("<a href="http://combubo.com/test.txt">http://combubo.com/test.txt</a>").<br><br>The call returns after ~ 15 seconds. Other servers take minutes to break the connection.<br><br>I located this in httpc_response.erl:
<br><br>whole_body(Body, Length) -><br> case size(Body) of<br> N when N < Length, N > 0-><br> {?MODULE, whole_body, [Body, Length]};<br> N when N >= Length, Length > 0 -><br> %% Potential trailing garbage will be thrown away in
<br> %% format_response/1 Some servers may send a 100-continue<br> %% response without the client requesting it through an<br> %% expect header in this case the trailing bytes may be<br> %% part of the real response message.
<br> {ok, Body};<br> _ -><br> {?MODULE, whole_body, [Body, Length]} <br> end.<br><br><br><br>and it seems this code doesn't handle the case of Length == 0, so I simply changed it to:<br><br><br>case size(Body) of
<br>
N when N < Length, N >= 0-><br>
{?MODULE, whole_body, [Body, Length]};<br>
N when N >= Length, Length >= 0 -><br><br><br>which seems to work fine for me, empty body responses now return right away.<br><br>Anyone know if I might have broken anything else by this patch, am I completely barking up the wrong tree?
<br><br>/Tobias<br><br><br>