diff options
author | Loïc Hoguin <[email protected]> | 2017-09-14 13:42:17 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2017-09-14 13:42:17 +0200 |
commit | 3cbf885961dc93df1b39d2de89f2a871402acbd5 (patch) | |
tree | 8f8f80ea6e6756fb5136cd6eff9bc03ea00cf481 /src/cowboy_http.erl | |
parent | 15ceaf1edff2a68e461fafd8cd77fc7f98918c8a (diff) | |
download | cowboy-3cbf885961dc93df1b39d2de89f2a871402acbd5.tar.gz cowboy-3cbf885961dc93df1b39d2de89f2a871402acbd5.tar.bz2 cowboy-3cbf885961dc93df1b39d2de89f2a871402acbd5.zip |
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.
Diffstat (limited to 'src/cowboy_http.erl')
-rw-r--r-- | src/cowboy_http.erl | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl index 5ee5ceb..c9c6383 100644 --- a/src/cowboy_http.erl +++ b/src/cowboy_http.erl @@ -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. |