Skip to content

Commit

Permalink
Add support for ignoring 100 Continue responses.
Browse files Browse the repository at this point in the history
--HG--
branch : 1.2
  • Loading branch information
oscarh committed Jan 21, 2010
1 parent 1f3f075 commit 27ab7cf
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/lhttpc_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ send_request(State) ->
case lhttpc_sock:send(Socket, Request, Ssl) of
ok ->
lhttpc_sock:setopts(Socket, [{packet, http}], Ssl),
read_response(State, nil, nil, [], <<>>);
read_response(State, nil, {nil, nil}, [], <<>>);
{error, closed} ->
lhttpc_sock:close(Socket, Ssl),
NewState = State#client_state{
Expand All @@ -164,16 +164,24 @@ send_request(State) ->
erlang:error(Reason)
end.

read_response(State, Vsn, Status, Hdrs, Body) ->
read_response(State, Vsn, {StatusCode, _} = Status, Hdrs, Body) ->
Socket = State#client_state.socket,
Ssl = State#client_state.ssl,
case lhttpc_sock:recv(Socket, Ssl) of
{ok, {http_response, NewVsn, StatusCode, Reason}} ->
NewStatus = {StatusCode, Reason},
{ok, {http_response, NewVsn, NewStatusCode, Reason}} ->
NewStatus = {NewStatusCode, Reason},
read_response(State, NewVsn, NewStatus, Hdrs, Body);
{ok, {http_header, _, Name, _, Value}} ->
Header = {lhttpc_lib:maybe_atom_to_list(Name), Value},
read_response(State, Vsn, Status, [Header | Hdrs], Body);
{ok, http_eoh} when StatusCode >= 100, StatusCode =< 199 ->
% RFC 2616, section 10.1:
% A client MUST be prepared to accept one or more
% 1xx status responses prior to a regular
% response, even if the client does not expect a
% 100 (Continue) status message. Unexpected 1xx
% status responses MAY be ignored by a user agent.
read_response(State, nil, {nil, nil}, [], <<>>);
{ok, http_eoh} ->
lhttpc_sock:setopts(Socket, [{packet, raw}], Ssl),
Method = State#client_state.method,
Expand Down

0 comments on commit 27ab7cf

Please sign in to comment.