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

remove macros

This commit is contained in:
geeksilva97 2024-01-10 15:46:18 -03:00
parent aab248a37e
commit 9bfc95d17f

View file

@ -15,9 +15,6 @@
-module(cowboy_req). -module(cowboy_req).
-define(INVALID_COOKIE_HEADER_ERROR, exit({response_error, invalid_header,
'The set-cookie header is special and must be set using cowboy_req:set_resp_cookie/3,4.'})).
%% Request. %% Request.
-export([method/1]). -export([method/1]).
-export([version/1]). -export([version/1]).
@ -722,7 +719,8 @@ set_resp_cookie(Name, Value, Req, Opts) ->
-spec set_resp_header(binary(), iodata(), Req) -spec set_resp_header(binary(), iodata(), Req)
-> Req when Req::req(). -> Req when Req::req().
set_resp_header(<<"set-cookie">>, _, _) -> set_resp_header(<<"set-cookie">>, _, _) ->
?INVALID_COOKIE_HEADER_ERROR; exit({response_error, invalid_header,
'The set-cookie header is special and must be set using cowboy_req:set_resp_cookie/3,4.'});
set_resp_header(Name, Value, Req=#{resp_headers := RespHeaders}) -> set_resp_header(Name, Value, Req=#{resp_headers := RespHeaders}) ->
Req#{resp_headers => RespHeaders#{Name => Value}}; Req#{resp_headers => RespHeaders#{Name => Value}};
set_resp_header(Name,Value, Req) -> set_resp_header(Name,Value, Req) ->
@ -731,7 +729,8 @@ set_resp_header(Name,Value, Req) ->
-spec set_resp_headers(cowboy:http_headers(), Req) -spec set_resp_headers(cowboy:http_headers(), Req)
-> Req when Req::req(). -> Req when Req::req().
set_resp_headers(#{<<"set-cookie">> := _}, _) -> set_resp_headers(#{<<"set-cookie">> := _}, _) ->
?INVALID_COOKIE_HEADER_ERROR; exit({response_error, invalid_header,
'The set-cookie header is special and must be set using cowboy_req:set_resp_cookie/3,4.'});
set_resp_headers(Headers, Req=#{resp_headers := RespHeaders}) -> set_resp_headers(Headers, Req=#{resp_headers := RespHeaders}) ->
Req#{resp_headers => maps:merge(RespHeaders, Headers)}; Req#{resp_headers => maps:merge(RespHeaders, Headers)};
set_resp_headers(Headers, Req) -> set_resp_headers(Headers, Req) ->
@ -789,7 +788,8 @@ inform(_, _, #{has_sent_resp := _}) ->
exit({response_error, response_already_sent, exit({response_error, response_already_sent,
'The final response has already been sent.'}); 'The final response has already been sent.'});
inform(_, #{<<"set-cookie">> := _}, _) -> inform(_, #{<<"set-cookie">> := _}, _) ->
?INVALID_COOKIE_HEADER_ERROR; exit({response_error, invalid_header,
'The set-cookie header is special and must be set using cowboy_req:set_resp_cookie/3,4.'});
inform(Status, Headers, Req) when is_integer(Status); is_binary(Status) -> inform(Status, Headers, Req) when is_integer(Status); is_binary(Status) ->
cast({inform, Status, Headers}, Req). cast({inform, Status, Headers}, Req).
@ -810,7 +810,8 @@ reply(_, _, _, #{has_sent_resp := _}) ->
exit({response_error, response_already_sent, exit({response_error, response_already_sent,
'The final response has already been sent.'}); 'The final response has already been sent.'});
reply(_, #{<<"set-cookie">> := _}, _, _) -> reply(_, #{<<"set-cookie">> := _}, _, _) ->
?INVALID_COOKIE_HEADER_ERROR; exit({response_error, invalid_header,
'The set-cookie header is special and must be set using cowboy_req:set_resp_cookie/3,4.'});
reply(Status, Headers, {sendfile, _, 0, _}, Req) reply(Status, Headers, {sendfile, _, 0, _}, Req)
when is_integer(Status); is_binary(Status) -> when is_integer(Status); is_binary(Status) ->
do_reply(Status, Headers#{ do_reply(Status, Headers#{
@ -869,7 +870,8 @@ stream_reply(_, _, #{has_sent_resp := _}) ->
exit({response_error, response_already_sent, exit({response_error, response_already_sent,
'The final response has already been sent.'}); 'The final response has already been sent.'});
stream_reply(_, #{<<"set-cookie">> := _}, _) -> stream_reply(_, #{<<"set-cookie">> := _}, _) ->
?INVALID_COOKIE_HEADER_ERROR; exit({response_error, invalid_header,
'The set-cookie header is special and must be set using cowboy_req:set_resp_cookie/3,4.'});
%% 204 and 304 responses must NOT send a body. We therefore %% 204 and 304 responses must NOT send a body. We therefore
%% transform the call to a full response and expect the user %% transform the call to a full response and expect the user
%% to NOT call stream_body/3 afterwards. (RFC7230 3.3) %% to NOT call stream_body/3 afterwards. (RFC7230 3.3)
@ -922,7 +924,8 @@ stream_events(Events, IsFin, Req=#{has_sent_resp := headers}) ->
-spec stream_trailers(cowboy:http_headers(), req()) -> ok. -spec stream_trailers(cowboy:http_headers(), req()) -> ok.
stream_trailers(#{<<"set-cookie">> := _}, _) -> stream_trailers(#{<<"set-cookie">> := _}, _) ->
?INVALID_COOKIE_HEADER_ERROR; exit({response_error, invalid_header,
'The set-cookie header is special and must be set using cowboy_req:set_resp_cookie/3,4.'});
stream_trailers(Trailers, Req=#{has_sent_resp := headers}) -> stream_trailers(Trailers, Req=#{has_sent_resp := headers}) ->
cast({trailers, Trailers}, Req). cast({trailers, Trailers}, Req).