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

Add persistent_term support to the router

This commit is contained in:
Loïc Hoguin 2019-09-28 15:40:41 +02:00
parent 7bccad4d21
commit cf84f59d9b
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
5 changed files with 80 additions and 3 deletions

View file

@ -160,7 +160,11 @@ compile_brackets_split(<< C, Rest/bits >>, Acc, N) ->
-spec execute(Req, Env)
-> {ok, Req, Env} | {stop, Req}
when Req::cowboy_req:req(), Env::cowboy_middleware:env().
execute(Req=#{host := Host, path := Path}, Env=#{dispatch := Dispatch}) ->
execute(Req=#{host := Host, path := Path}, Env=#{dispatch := Dispatch0}) ->
Dispatch = case Dispatch0 of
{persistent_term, Key} -> persistent_term:get(Key);
_ -> Dispatch0
end,
case match(Dispatch, Host, Path) of
{ok, Handler, HandlerOpts, Bindings, HostInfo, PathInfo} ->
{ok, Req#{