mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Add {set_options, #{metrics_user_data := Map}}
This allows giving custom metadata to the metrics stream handler. This can be useful to for example provide the name of the module handling the request which is only known after routing. But any user data is allowed. When called multiple times the user data maps are merged.
This commit is contained in:
parent
a14ecf19c6
commit
f673e191b3
3 changed files with 43 additions and 14 deletions
|
@ -32,4 +32,9 @@ set_options(<<"idle_timeout_long">>, Req0, State) ->
|
|||
#{pid := Pid, streamid := StreamID} = Req0,
|
||||
Pid ! {{Pid, StreamID}, {set_options, #{idle_timeout => 60000}}},
|
||||
{_, Body, Req} = cowboy_req:read_body(Req0),
|
||||
{ok, cowboy_req:reply(200, #{}, Body, Req), State}.
|
||||
{ok, cowboy_req:reply(200, #{}, Body, Req), State};
|
||||
set_options(<<"metrics_user_data">>, Req, State) ->
|
||||
%% @todo This should be replaced by a cowboy_req:cast/cowboy_stream:cast.
|
||||
#{pid := Pid, streamid := StreamID} = Req,
|
||||
Pid ! {{Pid, StreamID}, {set_options, #{metrics_user_data => #{handler => ?MODULE}}}},
|
||||
{ok, cowboy_req:reply(200, #{}, <<"Hello world!">>, Req), State}.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue