dvv/stable — pull request #2 by fishcakez (2013-05-25 19:44:12+00:00)
Title: Should cowboy_resource be a cowboy_sub_protocol?

I haven't run this code (don't have R16 here atm, so query atom causes issues) but I want to start a debate about the correct way to dispatch to custom handlers.

I thought the correct way was to do as this patch does, call {upgrade, ...} in Handler:init/3, then inside the sub_protocol:
```erlang
%% Dispatch
{dispatch, [{"/", Handler, HandlerOpts}]}
%% Handler.erl
init(_Transport, Req, Opts) ->
{upgrade, protocol, SubProtocol}.
%% SubProtocol.erl
upgrade(Req, Env, Handler, HandlerState) ->
NestedSubProtocol:upgrade(Req, Env, ?MODULE, {state, Handler, HandlerState}).
```

But it seems, from looking around github, that no one does this.