mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-16 13:10:24 +00:00
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.
This commit is contained in:
parent
1f4c1e2c67
commit
5269bf580b
2 changed files with 47 additions and 4 deletions
|
@ -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.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue