anchor.diff:                                 Req).
   
   do_init(Req, Access, Iorio, IorioState, Active) ->
  -    {Token, Req1} = cowboy_req:qs_val(<<"jwt">>, Req, nil),
  -    {Params, Req2} = cowboy_req:qs_vals(Req1),
  +    {Token, Req0} = cowboy_req:qs_val(<<"jwt">>, Req, nil),
  +    {Params, Req1} = cowboy_req:qs_vals(Req0),
  +    {ConnType, Req2} = connection_type(Req1, Active),
  +
       Req3 = cowboy_req:compact(Req2),
       RawSubs = proplists:get_all_values(<<"s">>, Params),
       Subs = iorio_parse:subscriptions(RawSubs),
  
positive.code: -include("include/iorio.hrl").
  
  -record(state, {channels=[], iorio_mod, iorio_state, token, info, access,
                  active}).
  
  % TODO: handle CORS in COMET on bullet?
  init(_Transport, Req, Opts, Active) ->
      {access, Access} = proplists:lookup(access, Opts),
      {iorio_mod, Iorio} = proplists:lookup(iorio_mod, Opts),
      {iorio_state, IorioState} = proplists:lookup(iorio_state, Opts),
      {Method, Req1} = cowboy_req:method(Req),
      case Method of
          <<"GET">> -> do_init(Req1, Access, Iorio, IorioState, Active);
  
negative.code:             lager:warning("shutdown listen ~p", [Reason]),
              {shutdown, Req3, #state{}}
      end.
  
  connection_type(Req, once) -> {xhr, Req};
  connection_type(Req, false) -> {post, Req};
  connection_type(Req, true) ->
  	case cowboy_req:header(<<"upgrade">>, Req) of
  		{undefined, Req1} ->
              {sse, Req1};
  		{Bin, Req1} when is_binary(Bin) ->
  			case cowboy_bstr:to_lower(Bin) of
  				<<"websocket">> ->
                      {ws, Req1};
  				_Any ->
                      {unknown, Req}
  			end
  	end.
  