mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Don't crash in delete_resp_header if no resp headers are set
This commit is contained in:
parent
82cd22a88b
commit
3a7b411143
2 changed files with 11 additions and 5 deletions
|
@ -688,7 +688,10 @@ has_resp_body(_) ->
|
||||||
-spec delete_resp_header(binary(), Req)
|
-spec delete_resp_header(binary(), Req)
|
||||||
-> Req when Req::req().
|
-> Req when Req::req().
|
||||||
delete_resp_header(Name, Req=#{resp_headers := RespHeaders}) ->
|
delete_resp_header(Name, Req=#{resp_headers := RespHeaders}) ->
|
||||||
Req#{resp_headers => maps:remove(Name, RespHeaders)}.
|
Req#{resp_headers => maps:remove(Name, RespHeaders)};
|
||||||
|
%% There are no resp headers so we have nothing to delete.
|
||||||
|
delete_resp_header(Name, Req) ->
|
||||||
|
Req.
|
||||||
|
|
||||||
-spec inform(cowboy:http_status(), req()) -> ok.
|
-spec inform(cowboy:http_status(), req()) -> ok.
|
||||||
inform(Status, Req) ->
|
inform(Status, Req) ->
|
||||||
|
|
|
@ -94,10 +94,13 @@ do(<<"has_resp_body">>, Req0, Opts) ->
|
||||||
{ok, cowboy_req:reply(200, #{}, Req), Opts}
|
{ok, cowboy_req:reply(200, #{}, Req), Opts}
|
||||||
end;
|
end;
|
||||||
do(<<"delete_resp_header">>, Req0, Opts) ->
|
do(<<"delete_resp_header">>, Req0, Opts) ->
|
||||||
false = cowboy_req:has_resp_header(<<"content-type">>, Req0),
|
%% We try to delete first even though it hasn't been set to
|
||||||
Req1 = cowboy_req:set_resp_header(<<"content-type">>, <<"text/plain">>, Req0),
|
%% make sure this noop is possible.
|
||||||
true = cowboy_req:has_resp_header(<<"content-type">>, Req1),
|
Req1 = cowboy_req:delete_resp_header(<<"content-type">>, Req0),
|
||||||
Req = cowboy_req:delete_resp_header(<<"content-type">>, Req1),
|
false = cowboy_req:has_resp_header(<<"content-type">>, Req1),
|
||||||
|
Req2 = cowboy_req:set_resp_header(<<"content-type">>, <<"text/plain">>, Req1),
|
||||||
|
true = cowboy_req:has_resp_header(<<"content-type">>, Req2),
|
||||||
|
Req = cowboy_req:delete_resp_header(<<"content-type">>, Req2),
|
||||||
false = cowboy_req:has_resp_header(<<"content-type">>, Req),
|
false = cowboy_req:has_resp_header(<<"content-type">>, Req),
|
||||||
{ok, cowboy_req:reply(200, #{}, "OK", Req), Opts};
|
{ok, cowboy_req:reply(200, #{}, "OK", Req), Opts};
|
||||||
do(<<"inform2">>, Req0, Opts) ->
|
do(<<"inform2">>, Req0, Opts) ->
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue