0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 20:30:23 +00:00

Don't send an unnecessary content-type header with cowboy_rest

This commit is contained in:
Loïc Hoguin 2018-11-14 15:40:09 +01:00
parent 1e2d59ed26
commit 637a9b3924
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
2 changed files with 11 additions and 4 deletions

View file

@ -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}) ->