aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-05-18 18:03:56 +0200
committerLoïc Hoguin <[email protected]>2018-05-18 18:38:26 +0200
commit5229d790fb720ea340171e4b290cffdce9c68197 (patch)
tree4a9991defeddbd272bed5d8e6f90c3f71b45cd3f /src
parent763eef4e46dd8ffb5bb10ddccb1eb761971d8382 (diff)
downloadcowboy-5229d790fb720ea340171e4b290cffdce9c68197.tar.gz
cowboy-5229d790fb720ea340171e4b290cffdce9c68197.tar.bz2
cowboy-5229d790fb720ea340171e4b290cffdce9c68197.zip
Don't send transfer-encoding when streaming 204 responses
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_http.erl14
-rw-r--r--src/cowboy_stream_h.erl4
2 files changed, 9 insertions, 9 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};