-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 else can I set custom headers? #467
Comments
Why would the browser code be the problem here? Browsers don't even support custom headers. |
Hmmm, maybe I am just confused. Initially I thought the I guess, one is referring to the native browser code, the other one is like a mockup. Or am I interpreting this the wrong way? Ultimately I am after custom headers between client and server. |
If your "client" is actually a node script which uses the |
Yes, I am referring to browsers as clients. I see, I must have misinterpreted that code before. Sorry. So, how can I transfer data from the browser to the client during websocket initialisation? If custom headers are out of questions, what else is possible? Query strings? I cannot picture how query strings here because these are for GET requests only. But not for web sockets. Correct me if I am wrong. |
Query strings will work fine for WebSocket connections as upgrade requests contain the full URL path. On the server you can do something like |
Ah, you mean we can amend query parameters to the URL we are passing onto the WebSocket constructor? On the client something like
and on the server side an I can parse this with
That would be great! Will check this out tonight ... |
Yes, it worked. Thanks so much man! |
@3rd-Eden : |
@3rd-Eden @irshad-qb |
@streamnsight WebSocket = require 'ws'
ws = new WebSocket 'ws://localhost:8000',{
headers : {
token: getToken()
}
} |
@iostreamer-X The only place to set a cookie on the response is in the |
I am sorry I think I misunderstood the problem |
This work perfectly |
I know there were heavy discussions in #227 but it is not clear to me what the current state is.
All I need is the ability to set custom headers for an API I am working on. Without this functionality everything would become a lot more complicated. If I look at https://github.com/websockets/ws/blob/master/lib/WebSocket.js#L49, I can see that
options
are already supported.The problem obviously lies here
https://github.com/websockets/ws/blob/master/lib/browser.js#L33
Anyone?
The text was updated successfully, but these errors were encountered: