mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Add cowboy_req:delete_resp_header/2
Both requested and better for making Req opaque.
This commit is contained in:
parent
527477bd4a
commit
e13ab806ea
2 changed files with 10 additions and 4 deletions
|
@ -71,6 +71,7 @@
|
|||
-export([set_resp_body_fun/3]).
|
||||
-export([has_resp_header/2]).
|
||||
-export([has_resp_body/1]).
|
||||
-export([delete_resp_header/2]).
|
||||
-export([reply/2]).
|
||||
-export([reply/3]).
|
||||
-export([reply/4]).
|
||||
|
@ -724,7 +725,6 @@ set_resp_header(Name, Value, Req=#http_req{resp_headers=RespHeaders}) ->
|
|||
set_resp_body(Body, Req) ->
|
||||
{ok, Req#http_req{resp_body=Body}}.
|
||||
|
||||
|
||||
%% @doc Add a body function to the response.
|
||||
%%
|
||||
%% The response body may also be set to a content-length - stream-function pair.
|
||||
|
@ -757,6 +757,13 @@ has_resp_body(#http_req{resp_body={Length, _}}) ->
|
|||
has_resp_body(#http_req{resp_body=RespBody}) ->
|
||||
iolist_size(RespBody) > 0.
|
||||
|
||||
%% Remove a header previously set for the response.
|
||||
-spec delete_resp_header(cowboy_http:header(), Req)
|
||||
-> Req when Req::req().
|
||||
delete_resp_header(Name, Req=#http_req{resp_headers=RespHeaders}) ->
|
||||
RespHeaders2 = lists:keydelete(Name, 1, RespHeaders),
|
||||
Req#http_req{resp_headers=RespHeaders2}.
|
||||
|
||||
%% @equiv reply(Status, [], [], Req)
|
||||
-spec reply(cowboy_http:status(), Req) -> {ok, Req} when Req::req().
|
||||
reply(Status, Req=#http_req{resp_body=Body}) ->
|
||||
|
|
|
@ -579,9 +579,8 @@ if_modified_since(Req, State, IfModifiedSince) ->
|
|||
end
|
||||
end.
|
||||
|
||||
not_modified(Req=#http_req{resp_headers=RespHeaders}, State) ->
|
||||
RespHeaders2 = lists:keydelete(<<"Content-Type">>, 1, RespHeaders),
|
||||
Req2 = Req#http_req{resp_headers=RespHeaders2},
|
||||
not_modified(Req, State) ->
|
||||
Req2 = cowboy_req:delete_resp_header(<<"Content-Type">>, Req),
|
||||
{Req3, State2} = set_resp_etag(Req2, State),
|
||||
{Req4, State3} = set_resp_expires(Req3, State2),
|
||||
respond(Req4, State3, 304).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue