New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to set initially cookies to a websocket client #473
Comments
In the node.js variant you can supply an options object with a headers key where you can add the Cookie header your self. |
What is the node.js variant? still in ws? Could you show a code example please? |
I think he means in node WebSocket server you can write
|
+1 set cookie in node js ? ws |
Hello! I need to set cookie. This decision is not work ((( ! ** In console: But in client cookie not setted, in ws.upgradeReq.headers (on connection event) is not setted! Is there any way to set cookie ( ? PS: I use WSS |
@eugen35 You've got something else overriding the Set-Cookie header with the cookie "repa" (and a timestamp as value) before sent by the server |
No its my experiments with sets of cookie. Any way cookie "repa" is felt on client and in response |
I find solution:
headers is a Array, not Object, because solution @mems , don`t work. |
code example
|
@whiler This worked for me when using ws as a web socket client in nodejs. Can you please provide a link to the documentation? |
@brenthmiras you might not need this any more, but here's the link you want: https://github.com/websockets/ws/blob/db1486492a00f5cd6b43bed06773668d54994593/doc/ws.md#new-websocketaddress-protocols-options |
Can I know, how to receive or get, the cookie which be set in server side? var responseHeader = make(http.Header)
var cookie = &http.Cookie{
Name: "foo",
Value: "bar",
Secure: true,
}
responseHeader.Add("Set-Cookie", cookie.String()) What exact way, I can get this cookie, from client side if (window["WebSocket"]) {
let self = this
var wss = new WebSocket("wss://xxx.com/api/v5/wss/v3/wss")
wss.addEventListener("open", onOpenFunc)
function onOpenFunc(event) {
//how to get the cookie here?
} |
Looking at the doc, we can read cookies from a server, with upgradeReq, but from a client I don't see how to set cookies before making the connection
The text was updated successfully, but these errors were encountered: