0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-15 04:30:25 +00:00

Improve how we detect request errors

When the request process exits with a {request_error, Reason, Human}
exit reason, Cowboy will return a 400 status code instead of 500.
Cowboy may also return a more specific status code depending on
the error. Currently it may also return 408 or 413.

This should prove to be more solid that looking inside the stack
trace.
This commit is contained in:
Loïc Hoguin 2017-09-14 13:42:17 +02:00
parent 15ceaf1edf
commit 3cbf885961
No known key found for this signature in database
GPG key ID: 71366FF21851DF03
4 changed files with 139 additions and 32 deletions

View file

@ -785,8 +785,15 @@ commands(State, StreamID, [{flow, _Length}|Tail]) ->
commands(State, StreamID, Tail);
%% Error responses are sent only if a response wasn't sent already.
commands(State=#state{out_state=wait}, StreamID, [{error_response, StatusCode, Headers, Body}|Tail]) ->
commands(State, StreamID, [{response, StatusCode, Headers, Body}|Tail]);
commands(State=#state{out_state=wait}, StreamID, [{error_response, Status, Headers0, Body}|Tail]) ->
%% We close the connection when the error response is 408, as it
%% indicates a timeout and the RFC recommends that we stop here. (RFC7231 6.5.7)
Headers = case Status of
408 -> Headers0#{<<"connection">> => <<"close">>};
<<"408", _/bits>> -> Headers0#{<<"connection">> => <<"close">>};
_ -> Headers0
end,
commands(State, StreamID, [{response, Status, Headers, Body}|Tail]);
commands(State, StreamID, [{error_response, _, _, _}|Tail]) ->
commands(State, StreamID, Tail);
%% Send an informational response.