0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-15 20:50:24 +00:00

Introduce cowboy_req:set_meta/3 to set request metadata

This commit is contained in:
Loïc Hoguin 2012-09-15 22:51:37 +02:00
parent f65f7d19a8
commit 9ef94fb64e
3 changed files with 27 additions and 19 deletions

View file

@ -49,6 +49,7 @@
-export([cookies/1]).
-export([meta/2]).
-export([meta/3]).
-export([set_meta/3]).
%% Request body API.
-export([has_body/1]).
@ -429,6 +430,15 @@ meta(Name, Req, Default) ->
false -> {Default, Req}
end.
%% @doc Set metadata information.
%%
%% You can use this function to attach information about the request.
%%
%% If the value already exists it will be overwritten.
-spec set_meta(atom(), any(), Req) -> Req when Req::req().
set_meta(Name, Value, Req=#http_req{meta=Meta}) ->
Req#http_req{meta=[{Name, Value}|lists:keydelete(Name, 1, Meta)]}.
%% Request Body API.
%% @doc Return whether the request message has a body.