0

I'd like to be able to create a socket.io-client connection from a NodeJS process reusing an existing HTTP agent (like superagent or request) for the initial handshake. Thus, hopefully sending any relevant cookie with the HTTP request for the handshake.

This behaviour I expect is what already happens when socket.io-client is used in the browser and XHR makes the request for a handshake sending existing cookies for the domain/URL.

Osk
  • 198
  • 6

1 Answers1

1

Using the same HTTP agent will not solve your problem. By itself, nodejs does not save client cookies.

If you want to save them so they are sent with future client requests, you will have to save and send them yourself or get a module that helps do that for you.

See these other questions for reference:

NodeJS and HTTP Client - Are cookies supported?

How do I create a HTTP Client Request with a cookie?

How to maintain a request session in NodeJS

Can I send a GET request with cookies in the headers in Node?

Making HTTP Requests in Node.js

The request module supports an option for a cookie jar which will remember cookies for you.

Community
  • 1
  • 1
jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • Thanks for responding. I'm aware that request supports this option. So does superagent. Still, my question persists. Supposing I save the cookies as all of these links suggest, how can I specify socket.io-client to use this HTTP client instance for its handhsake. – Osk Oct 14 '15 at 23:33