-
Notifications
You must be signed in to change notification settings - Fork 17
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
Can not we set the header in the dial? #1
Comments
Oh @majidbigdeli I just saw it. It's the only one missing part of the neffos repo's javascript-equivalent example. It's already ready on my local machine but I didn't have enough time to test it yet (I am "designing" the new website for Iris too), I will push that feature tomorrow :) |
Just to give some details: For the browser: As you said there is no method in the JavaScript WebSockets API for specifying additional headers for the browser to send. Therefore we have 3-4 solutions:
For the nodejs side, the |
…on nodejs the http.request.options.headers object can be used as usual, rel: #1
Hello @kataras |
Updated For the nodejs: You can simply use the For the browser: I made it to accept the same dictionary for headers, so the same const conn = await neffos.dial(wsURL, {...}, {
headers: {
'X-Username': 'kataras',
}
}); Just a note for the browser-side: The Hope that helps @majidbigdeli |
…- more advanced examples are always located at https://github.com/kataras/neffos - rel: #1
@kataras . Your solution is very clever |
I used this solution for myself already.
|
Thank you a lot @majidbigdeli! Yeah the solution of yours is fine and you can still use it but, you know, we needed a way to separate any user-specific url parameters to the endpoint that meant to be used as |
Yes you are right . That's why I say that your solution is very clever. |
I know that There is no method in the JavaScript WebSockets API for specifying additional headers for the client/browser to send. The HTTP path ("GET /xyz") and protocol header ("Sec-WebSocket-Protocol") can be specified in the WebSocket constructor.
The Sec-WebSocket-Protocol header (which is sometimes extended to be used in websocket specific authentication) is generated from the optional second argument to the WebSocket constructor:
The above results in the following headers:
Sec-WebSocket-Protocol: protocol
and
Sec-WebSocket-Protocol: protocol1, protocol2
but I have error
my index.html
I used Query String to solve this problem.
change wsURL to ws://localhost:3811/echo?UserId=123
and remove ["123"] protocol in the dial method.
Can not we have a custom header on dial?
Like golang client
The text was updated successfully, but these errors were encountered: