mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Forward transport and protocol name to Handler:init.
This commit is contained in:
parent
e0185dd27f
commit
7888be00d2
2 changed files with 5 additions and 4 deletions
|
@ -63,9 +63,9 @@ use one of the predefined handlers or write your own. An hello world HTTP
|
||||||
handler could be written like this:
|
handler could be written like this:
|
||||||
|
|
||||||
-module(my_handler).
|
-module(my_handler).
|
||||||
-export([init/2, handle/2, terminate/2]).
|
-export([init/3, handle/2, terminate/2]).
|
||||||
|
|
||||||
init(Req, Opts) ->
|
init({tcp, http}, Req, Opts) ->
|
||||||
{ok, Req, undefined}.
|
{ok, Req, undefined}.
|
||||||
|
|
||||||
handle(Req, State) ->
|
handle(Req, State) ->
|
||||||
|
|
|
@ -130,8 +130,9 @@ header(http_eoh, Req, State) ->
|
||||||
handler_init(Req, State).
|
handler_init(Req, State).
|
||||||
|
|
||||||
-spec handler_init(Req::#http_req{}, State::#state{}) -> ok.
|
-spec handler_init(Req::#http_req{}, State::#state{}) -> ok.
|
||||||
handler_init(Req, State=#state{handler={Handler, Opts}}) ->
|
handler_init(Req, State=#state{
|
||||||
case catch Handler:init(Req, Opts) of
|
transport=Transport, handler={Handler, Opts}}) ->
|
||||||
|
case catch Handler:init({Transport:name(), http}, Req, Opts) of
|
||||||
{ok, Req, HandlerState} ->
|
{ok, Req, HandlerState} ->
|
||||||
handler_loop(HandlerState, Req, State);
|
handler_loop(HandlerState, Req, State);
|
||||||
%% @todo {upgrade, transport, Module}; {upgrade, protocol, Module}
|
%% @todo {upgrade, transport, Module}; {upgrade, protocol, Module}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue