Permalink
Browse files

Add support for ignoring 100 Continue responses.

--HG--
branch : 1.2
  • Loading branch information...
1 parent 1f3f075 commit 27ab7cf3dfe22fee5359435724e6802bf5380fb6 @oscarh oscarh committed Jan 21, 2010
Showing with 12 additions and 4 deletions.
  1. +12 −4 src/lhttpc_client.erl
View
@@ -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{
@@ -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,

0 comments on commit 27ab7cf

Please sign in to comment.