[99s-extend] cowboy_http_handler type spec

Loïc Hoguin essen at ninenines.eu
Wed Oct 31 00:43:06 CET 2012


On 10/31/2012 12:38 AM, rambocoder wrote:
> Hi everyone, newb questions here:
>
> Is the reason why the type specification for the init callback lists
> various "{loop,..." tuples, because a single module can implement
> cowboy_loop_handler and cowboy_http_handler?
> And this way, a dializier warning will not be triggered?
> https://github.com/extend/cowboy/blob/master/src/cowboy_http_handler.erl#L39

Yes that's exactly why. Not the best solution but good enough.

> Because looking at the handler code,
> https://github.com/extend/cowboy/blob/master/src/cowboy_protocol.erl#L473 if
> the {loop, * is returned from init, then the handle(Req,State) will not
> be processed.

You have this one if you just want loops:

https://github.com/extend/cowboy/blob/master/src/cowboy_loop_handler.erl

Having an identical init in both allows us to use the 2 handlers without 
Dialyzer complaining.

> Also, is it safe to say that Handler:init is like "before" in lot's of
> web frameworks. I can place validation\authentication logic there.

Definitely, prepare what you need in init, do what you need to do in 
handle and clean up in terminate if needed.

-- 
Loïc Hoguin
Erlang Cowboy
Nine Nines
http://ninenines.eu



More information about the Extend mailing list