0

I'm currently using node.js websocket module in my project. There is PHPSESSID in my browser but not in websocket's request header

 Accept-Encoding:gzip, deflate, sdch
 Accept-Language:en-US,en;q=0.8,ka;q=0.6,ru;q=0.4
 Cache-Control:no-cache
 Connection:Upgrade
 Host:someHost
 Origin:someOrigin
 Pragma:no-cache
 Sec-WebSocket-Extensions:permessage-deflate; client_max_window_bits
 Sec-WebSocket-Key:0Hq9BZfHAxIMbfu3cJpWyg==
 Sec-WebSocket-Protocol:echo-protocol
 Sec-WebSocket-Version:13
 Upgrade:websocket
 User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36

I have checked it in my server side code

 wsServer.on('request', function(request) {
      console.log(request.cookies);
 });

and it prints an empty array [].

How can I send cookie via websocket? Should I use headers or something else?

Paramore
  • 1,313
  • 2
  • 19
  • 37
  • Are you hosting your websocket server on the same domain as your cookies? – Hurricane Hamilton Dec 21 '15 at 18:53
  • Yes, both are on the same domain. – Paramore Dec 21 '15 at 18:55
  • From your dump of headers, it looks like the browser is never sending the cookies, so we need to identify why the browser isn't sending them. – Hurricane Hamilton Dec 21 '15 at 19:13
  • Yes, I think is a strange behavior. I have javascript code on the client side `alert(document.cookie)` and it alerts `PHPSESSID=dekq8b7edlre6culggvbcblch7`, but there is no cookie in websoket's header – Paramore Dec 21 '15 at 19:18
  • Could it be an issue with secure cookies? Have a look at the very bottom of this answer: http://stackoverflow.com/questions/22285299/use-session-data-on-websocket-handshake – Hurricane Hamilton Dec 21 '15 at 19:29
  • Yes, as you mentioned there is something wrong with google chrome. I tested it on Firefox and it sends cookie via websocket. – Paramore Dec 22 '15 at 07:01

0 Answers0