anchor.diff:              cowboy_req:set_resp_header(<<"access-control-allow-credentials">>, <<"true">>, Req1)
       end.
   
  -encode_polling_packets_v1(PacketList) ->
  +encode_polling_xhr_packets_v1(PacketList) ->
       lists:foldl(fun(Packet, AccIn) ->
           PacketLen = [list_to_integer([D]) || D <- integer_to_list(byte_size(Packet))],
           PacketLenBin = list_to_binary(PacketLen),
           <<AccIn/binary, 0, PacketLenBin/binary, 255, Packet/binary>>
  -    end, <<>>, PacketList).+    end, <<>>, PacketList).
  +
  +encode_polling_json_packets_v1(PacketList, JsonP) ->
  +    Payload = lists:foldl(fun(Packet, AccIn) ->
  +        ResultLenBin = integer_to_binary(byte_size(Packet)),
  +        Rs = binary:replace(Packet, <<"\"">>, <<"\\\"">>, [global]),
  +        <<AccIn/binary, ResultLenBin/binary, ":", Rs/binary>>
  +    end, <<>>, PacketList),
  +    <<"___eio[", JsonP/binary, "](\"", Payload/binary, "\");">>.
positive.code:                                end,
                      case socketio_session:recv(Pid, Messages) of
                          noproc ->
                              {shutdown, Req, #http_state{action = error, config = Config, sid = Sid, version = Version}};
                          _ ->
                              {ok, Req1, #http_state{action = ok, config = Config, sid = Sid, version = Version}}
                      end;
                  {error, _} ->
                      {shutdown, Req, #http_state{action = error, config = Config, sid = Sid, version = Version}}
              end;
          {{error, not_found}, _} ->
              {ok, Req, #http_state{action = not_found, sid = Sid, config = Config, version = Version}};
          _ ->
              {ok, Req, #http_state{action = error, sid = Sid, config = Config, version = Version}}
      end.
  
  %% Websocket handlers
  
negative.code:             error
      end.
  
  safe_poll(Req, HttpState = #http_state{config = Config = #config{protocol = Protocol}, version = Version, jsonp = JsonP}, Pid, WaitIfEmpty) ->
      try
          Messages = socketio_session:poll(Pid),
          case {WaitIfEmpty, Messages} of
              {true, []} when Version =:= 1 ->
                  case socketio_session:transport(Pid) of
                      websocket ->
                          {ok, Req1} = reply_messages(Req, [], Config, true, Version, JsonP),
                          {ok, Req1, HttpState};
                      _ ->
                          {loop, Req, HttpState, hibernate}
  