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 request headers when connect to server? #722
Comments
I also need that... Did you find any solution? |
i am also interested in this. I've seen how to do it on the Java socket.io-client but not the JS one |
Won't Work with all transport-methods. http://stackoverflow.com/questions/4361173/http-headers-in-websockets-client-apic I'm searching for a solution to. |
What are you trying to achieve? Can't you use url parameters? |
I'm trying to write a test to verify whether websockets can be eavesdropped on before and after authentication middleware. In order to successfully authenticate, however, I need to send a cookie session along with the initial http upgrade request. It works in the browser, I just want it to work in my node tests as well. |
Is there any progress on this? Or any hint how to get/set the cookie-session / sessionId within socket.io? |
I actually got it working. The details of the initial http handshake are available at
|
Since version const socket = io({
transportOptions: {
polling: {
extraHeaders: {
'x-clientid': 'abc'
}
}
}
}); |
How can I add url to this example |
@muhammadnasr Pass the options in the second argument, the first one being the url: const socket = io("/your-url-here", {
transportOptions: {
polling: {
extraHeaders: {
'x-clientid': 'abc'
}
}
}
}); |
That's great. Do you have sample code to set headers for iOS and Android SDK? Thanks a lot. |
Android : socketio/socket.io-client-java#226 |
Can the headers be dynamically set? |
For future readers: please see https://socket.io/docs/v3/client-initialization/#extraHeaders |
how to set custom request headers when connect socket.io use js client
The text was updated successfully, but these errors were encountered: