Bug in http client code (httpc_handler)

Erik Reitsma EJ (RY/ETM) <>
Mon Oct 20 14:05:56 CEST 2003


Hi,

I have found what seems to me like a bug in httpc_handler in inets-3.0.7 (and also in inets-3.0.6). The problem is, that in some situation the body of an HTTP POST is sent twice.

When I do an HTTP POST to a .NET server, the .NET server responds with a 100-continue, whether I ask for it or not. In the documentation of httpc_handler:status_continue/2 it says, that this should be ignored if the request has already been completed. In my case, this is already completed, because the POST body is sent immediately if I do not specify that I wish to expect the 100-continue. Therefore the body gets sent twice: once at the initial request, and again when the .NET server sends the status code 100.

I have replaced the implementation of httpc_handler:status_continue/2 with the following code:

status_continue(Req,Session) ->
    Headers = Req#request.headers,
    Method = Req#request.method,
    if
	Method==post;Method==put ->
	    case Headers#req_headers.expect of
		"100-continue" ->
		    %% only in this case we have not yet send the body
		    {_,Body}=Req#request.content,
		    http_lib:send(Session#tcp_session.scheme,Session#tcp_session.socket,Body),
		    next_response_with_request(Req,Session);
		_ ->
		    %% in other cases the status code should be ignored
		    next_response_with_request(Req,Session)
	    end;
	true ->
	    %% in other cases the status code should be ignored
	    next_response_with_request(Req,Session)
    end.

This seems to me to be a more correct implementation of the comments in the original source of httpc_handler. It solves the problem I had and should not break anything.
For inets-3.0.6, #tcp_session should be replaced by #session.

*Erik.




More information about the erlang-bugs mailing list