pladaria / reconnecting-websocket

Reconnecting WebSocket. For Web, React Native, cli (Node.js)
MIT License
1.22k stars 197 forks source link

Support for Cookie header in React Native #40

Closed mschipperheyn closed 6 years ago

mschipperheyn commented 6 years ago

I'm reopening this since this library wants to support React Native. And in websockets that depend on cookies (such as Spring), you need to be able to pass a cookie header.

I found that in current versions of React Native, you have to pass this header as an option like so

new WebSocket(url, protocols, {
    headers: {
         Cookie: [actual cookie data]
    }
});

This option is undocumented but apparent in the source code. I would hope that this real life RN scenario can be supported. https://github.com/pladaria/reconnecting-websocket/issues/35

pladaria commented 6 years ago

Are those cookies generated in client side (js)? AFAIK, httponly and secure cookies should work transparently, anyway I will investigate this. Btw, PRs are welcome

mschipperheyn commented 6 years ago

Regarding cookies, the code I use in my current reconnecting websocket is the one above.

But it looks like you're right. Seems like the cookies are passed transparently now. I don't know since what version.