aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cowboy_http.erl14
-rw-r--r--src/cowboy_stream_h.erl4
-rw-r--r--test/handlers/resp_h.erl21
3 files changed, 23 insertions, 16 deletions
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl
index 6cf31ff..8d9fd84 100644
--- a/src/cowboy_http.erl
+++ b/src/cowboy_http.erl
@@ -929,17 +929,19 @@ commands(State0=#state{socket=Socket, transport=Transport, streams=Streams}, Str
[{headers, StatusCode, Headers0}|Tail]) ->
%% @todo Same as above.
#stream{version=Version} = lists:keyfind(StreamID, #stream.id, Streams),
- {State1, Headers1} = case Version of
- 'HTTP/1.1' ->
- {State0, Headers0#{<<"transfer-encoding">> => <<"chunked">>}};
+ {State1, Headers1} = case {cow_http:status_to_integer(StatusCode), Version} of
+ {204, 'HTTP/1.1'} ->
+ {State0#state{out_state=done}, Headers0};
+ {_, 'HTTP/1.1'} ->
+ {State0#state{out_state=chunked}, Headers0#{<<"transfer-encoding">> => <<"chunked">>}};
%% Close the connection after streaming the data to HTTP/1.0 client.
%% @todo I'm guessing we need to differentiate responses with a content-length and others.
- 'HTTP/1.0' ->
- {State0#state{last_streamid=StreamID}, Headers0}
+ {_, 'HTTP/1.0'} ->
+ {State0#state{out_state=chunked, last_streamid=StreamID}, Headers0}
end,
{State, Headers} = connection(State1, Headers1, StreamID, Version),
Transport:send(Socket, cow_http:response(StatusCode, 'HTTP/1.1', headers_to_list(Headers))),
- commands(State#state{out_state=chunked}, StreamID, Tail);
+ commands(State, StreamID, Tail);
%% Send a response body chunk.
%%
%% @todo WINDOW_UPDATE stuff require us to buffer some data.
diff --git a/src/cowboy_stream_h.erl b/src/cowboy_stream_h.erl
index 620975c..7f72080 100644
--- a/src/cowboy_stream_h.erl
+++ b/src/cowboy_stream_h.erl
@@ -178,10 +178,8 @@ info(_StreamID, {read_body_timeout, _}, State) ->
%% We reset the expect field when a 100 continue response
%% is sent or when any final response is sent.
info(_StreamID, Inform = {inform, Status, _}, State0) ->
- State = case Status of
+ State = case cow_http:status_to_integer(Status) of
100 -> State0#state{expect=undefined};
- <<"100">> -> State0#state{expect=undefined};
- <<"100 ", _/bits>> -> State0#state{expect=undefined};
_ -> State0
end,
{[Inform], State};
diff --git a/test/handlers/resp_h.erl b/test/handlers/resp_h.erl
index 487a724..68b5fe0 100644
--- a/test/handlers/resp_h.erl
+++ b/test/handlers/resp_h.erl
@@ -169,17 +169,24 @@ do(<<"reply4">>, Req0, Opts) ->
end,
{ok, Req, Opts};
do(<<"stream_reply2">>, Req0, Opts) ->
- Req = case cowboy_req:binding(arg, Req0) of
+ case cowboy_req:binding(arg, Req0) of
<<"binary">> ->
- cowboy_req:stream_reply(<<"200 GOOD">>, Req0);
+ Req = cowboy_req:stream_reply(<<"200 GOOD">>, Req0),
+ stream_body(Req),
+ {ok, Req, Opts};
<<"error">> ->
ct_helper:ignore(cowboy_req, stream_reply, 3),
- cowboy_req:stream_reply(ok, Req0);
+ Req = cowboy_req:stream_reply(ok, Req0),
+ stream_body(Req),
+ {ok, Req, Opts};
+ <<"204">> ->
+ Req = cowboy_req:stream_reply(204, Req0),
+ {ok, Req, Opts};
Status ->
- cowboy_req:stream_reply(binary_to_integer(Status), Req0)
- end,
- stream_body(Req),
- {ok, Req, Opts};
+ Req = cowboy_req:stream_reply(binary_to_integer(Status), Req0),
+ stream_body(Req),
+ {ok, Req, Opts}
+ end;
do(<<"stream_reply3">>, Req0, Opts) ->
Req = case cowboy_req:binding(arg, Req0) of
<<"error">> ->