diff options
author | Loïc Hoguin <[email protected]> | 2017-12-06 16:30:30 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2017-12-06 16:30:30 +0100 |
commit | 5269bf580bc1bc75bb1afe59d52ef2c4772ff12d (patch) | |
tree | 9bd66256dee7d407c90705861c55ecb1e6f03896 /src/cowboy_http.erl | |
parent | 1f4c1e2c67fc343daafba3445a649e5273fdb557 (diff) | |
download | cowboy-5269bf580bc1bc75bb1afe59d52ef2c4772ff12d.tar.gz cowboy-5269bf580bc1bc75bb1afe59d52ef2c4772ff12d.tar.bz2 cowboy-5269bf580bc1bc75bb1afe59d52ef2c4772ff12d.zip |
Fix 408 not sending connection: close for HTTP/1.1
Also make sure the header is sent for all types of early_error
that result in the closing of the connection.
Diffstat (limited to 'src/cowboy_http.erl')
-rw-r--r-- | src/cowboy_http.erl | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl index 71b7099..bc8fbb9 100644 --- a/src/cowboy_http.erl +++ b/src/cowboy_http.erl @@ -1157,16 +1157,22 @@ error_terminate(StatusCode, State=#state{ref=Ref, peer=Peer, in_state=StreamStat end } end, - early_error(StatusCode, State, Reason, PartialReq), + early_error(StatusCode, State, Reason, PartialReq, #{<<"connection">> => <<"close">>}), terminate(State, Reason). +early_error(StatusCode, State, Reason, PartialReq) -> + early_error(StatusCode, State, Reason, PartialReq, #{}). + early_error(StatusCode0, #state{socket=Socket, transport=Transport, - opts=Opts, in_streamid=StreamID}, Reason, PartialReq) -> - Resp = {response, StatusCode0, RespHeaders0=#{<<"content-length">> => <<"0">>}, <<>>}, + opts=Opts, in_streamid=StreamID}, Reason, PartialReq, RespHeaders0) -> + RespHeaders1 = RespHeaders0#{<<"content-length">> => <<"0">>}, + Resp = {response, StatusCode0, RespHeaders1, <<>>}, try cowboy_stream:early_error(StreamID, Reason, PartialReq, Resp, Opts) of {response, StatusCode, RespHeaders, RespBody} -> Transport:send(Socket, [ cow_http:response(StatusCode, 'HTTP/1.1', maps:to_list(RespHeaders)), + %% @todo We shouldn't send the body when the method is HEAD. + %% @todo Technically we allow the sendfile tuple. RespBody ]) catch Class:Exception -> @@ -1176,7 +1182,7 @@ early_error(StatusCode0, #state{socket=Socket, transport=Transport, %% We still need to send an error response, so send what we initially %% wanted to send. It's better than nothing. Transport:send(Socket, cow_http:response(StatusCode0, - 'HTTP/1.1', maps:to_list(RespHeaders0))) + 'HTTP/1.1', maps:to_list(RespHeaders1))) end, ok. |