anchor.diff:  
       Result = <<":", HeartbeatTimeoutBin/binary, ":", SessionTimeoutBin/binary, ":websocket,xhr-polling">>,
       {ok, Req1} = cowboy_req:reply(200, text_headers(), <<Sid/binary, Result/binary>>, Req),
  -    {ok, Req1, Config};
  +    {ok, Req1, HttpState};
   
  -handle(Req, {data, Messages, Config}) ->
  +handle(Req, HttpState = #http_state{action = data, messages = Messages, config = Config}) ->
       {ok, Req1} = reply_messages(Req, Messages, Config),
  -    {ok, Req1, Config};
  +    {ok, Req1, HttpState};
   
  -handle(Req, {not_found, _Sid, Config}) ->
  +handle(Req, HttpState = #http_state{action = not_found}) ->
       {ok, Req1} = cowboy_req:reply(404, [], <<>>, Req),
  -    {ok, Req1, Config};
  +    {ok, Req1, HttpState};
   
  -handle(Req, {send, Config}) ->
  +handle(Req, HttpState = #http_state{action = send}) ->
       {ok, Req1} = cowboy_req:reply(200, [], <<>>, Req),
  -    {ok, Req1, Config};
  +    {ok, Req1, HttpState};
   
  -handle(Req, {session_in_use, Config}) ->
  +handle(Req, HttpState = #http_state{action = session_in_use}) ->
       {ok, Req1} = cowboy_req:reply(404, [], <<>>, Req),
  -    {ok, Req1, Config};
  +    {ok, Req1, HttpState};
   
  -handle(Req, {ok, Config}) ->
  +handle(Req, HttpState = #http_state{action = ok}) ->
       {ok, Req1} = cowboy_req:reply(200, text_headers(), <<>>, Req),
  -    {ok, Req1, Config};
  +    {ok, Req1, HttpState};
   
  -handle(Req, Config) ->
  +handle(Req, HttpState) ->
       {ok, Req1} = cowboy_req:reply(404, [], <<>>, Req),
  -    {ok, Req1, Config}.
  +    {ok, Req1, HttpState}.
   
  -info({timeout, _TRef, {?MODULE, Pid}}, Req, {heartbeat, Config}) ->
  -    safe_poll(Req, Config, Pid, false);
  +info({timeout, TRef, {?MODULE, Pid}}, Req, HttpState = #http_state{action = heartbeat, heartbeat_tref = TRef}) ->
  +    safe_poll(Req, HttpState#http_state{heartbeat_tref = undefined}, Pid, false);
   
  -info({message_arrived, Pid}, Req, {heartbeat, Config}) ->
  -    safe_poll(Req, Config, Pid, true);
  +info({message_arrived, Pid}, Req, HttpState = #http_state{action = heartbeat}) ->
  +    safe_poll(Req, HttpState, Pid, true);
   
  -info(_Info, Req, State) ->
  -    {ok, Req, State}.
  +info(_Info, Req, HttpState) ->
  +    {ok, Req, HttpState}.
   
  -terminate(_Req, _State) ->
  +terminate(_Req, _HttpState = #http_state{heartbeat_tref = undefined}) ->
  +    ok;
  +terminate(_Req, _HttpState = #http_state{heartbeat_tref = HeartbeatTRef}) ->
  +    erlang:cancel_timer(HeartbeatTRef),
       ok.
   
   text_headers() ->
  
positive.code:     end.
  
  %% Http handlers
  handle(Req, {create_session, Config = #config{heartbeat_timeout = HeartbeatTimeout,
                                                session_timeout = SessionTimeout,
                                                callback = Callback}}) ->
      Sid = uuids:new(),
  
      HeartbeatTimeoutBin = list_to_binary(integer_to_list(HeartbeatTimeout div 1000)),
  
negative.code:     Packet = Protocol:encode(Messages),
      cowboy_req:reply(200, text_headers(), Packet, Req).
  
  safe_poll(Req, HttpState = #http_state{config = Config = #config{protocol = Protocol}}, Pid, WaitIfEmpty) ->
      try
          Messages = socketio_session:poll(Pid),
          case {WaitIfEmpty, Messages} of
              {true, []} ->
                  {loop, Req, HttpState};
              _ ->
                  {ok, Req1} = reply_messages(Req, Messages, Config),
                  {ok, Req1, HttpState}
          end
      catch
          exit:{noproc, _} ->
              {ok, RD} = cowboy_req:reply(200, text_headers(), Protocol:encode(disconnect), Req),
              {ok, RD, HttpState#http_state{action = disconnect}}
      end.
  
  %% Websocket handlers
  