aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-11-14 15:40:09 +0100
committerLoïc Hoguin <[email protected]>2018-11-14 18:04:31 +0100
commit637a9b39249cf573b82d2493b7cedcf324b8537c (patch)
treed60dc7b587565ec107d7ada845d7cc2564fc94cf /src
parent1e2d59ed26a8de423fbaac26b6e9c315d257bfac (diff)
downloadcowboy-637a9b39249cf573b82d2493b7cedcf324b8537c.tar.gz
cowboy-637a9b39249cf573b82d2493b7cedcf324b8537c.tar.bz2
cowboy-637a9b39249cf573b82d2493b7cedcf324b8537c.zip
Don't send an unnecessary content-type header with cowboy_rest
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_rest.erl10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/cowboy_rest.erl b/src/cowboy_rest.erl
index b874692..606f47f 100644
--- a/src/cowboy_rest.erl
+++ b/src/cowboy_rest.erl
@@ -1595,7 +1595,15 @@ next(Req, State, Next) when is_function(Next) ->
next(Req, State, StatusCode) when is_integer(StatusCode) ->
respond(Req, State, StatusCode).
-respond(Req, State, StatusCode) ->
+respond(Req0, State, StatusCode) ->
+ %% We remove the content-type header when there is no body,
+ %% except when the status code is 200 because it might have
+ %% been intended (for example sending an empty file).
+ Req = case cowboy_req:has_resp_body(Req0) of
+ true when StatusCode =:= 200 -> Req0;
+ true -> Req0;
+ false -> cowboy_req:delete_resp_header(<<"content-type">>, Req0)
+ end,
terminate(cowboy_req:reply(StatusCode, Req), State).
switch_handler({switch_handler, Mod}, Req, #state{handler_state=HandlerState}) ->