gimite / web-socket-js

HTML5 Web Socket implementation powered by Flash
BSD 3-Clause "New" or "Revised" License
2.74k stars 490 forks source link

method to add cookies or headers #161

Closed borisreitman closed 9 years ago

borisreitman commented 9 years ago

Because HttpOnly cookies can not be accessed by Flash, I would like to set extra cookies or extra headers using javascript, so that when the Upgrade request is made by Flash, I can get at those headers and authenticate the user. Please provide either a way to set a custom header, or to add more cookies. Let me know if this is not clear, and more explanation is needed.

gimite commented 9 years ago

You can pass headers as the 5th argument of new WebSocket().

I haven't verified but something like this should work:

new WebSocket("ws://example.com/", null, null, null, "Header1: xxx\r\nHeader2: yyy\r\n");

I'm not sure, but this extra argument may cause error in native WebSocket. In that case, you must pass this argument only if Flash implementation is used.

borisreitman commented 9 years ago

Thanks, it works.