-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
Support for Set-Cookie response header from polling request #162
Comments
Also, if there are other headers that behave like |
Are you using the latest version of this package? |
I'm running the following:
|
Then I'm confused. Cookies send by the server in the HTTP transport are already passed on the websocket connection. Here is the relevant code that moves the cookies from HTTP to WS: https://github.com/miguelgrinberg/python-engineio/blob/master/engineio/client.py#L355-L360. Why do you think this isn't working for you? |
Seems like you're right. I directly looked at the cookies = 'connect.sid=' + connectsid + ';'
sio.connect('http://localhost:8080', headers={'cookie': cookies})
print(sio.eio.http.cookies) # shows that the cookie set in polling was successful, but not the cookie set with the headers functionality
print(sio.eio.http.headers) |
Okay, so if I understand this the problem occurs when you have some cookies given as a header and some more that are set during the HTTP transport exchange. So it works fine with one type of cookie or the other, but not with both together? That would mean that the websocket client gets confused if it gets cookies through the two arguments, and probably drops one of the sources of cookies. |
Yes. However I have yet to test the case where cookies are only given as headers. I am looking into setting up a minimum working example where the server does not set any cookies. |
This server does not send any var app = require('express')();
var http = require('http').createServer(app);
var io = require('socket.io')(http, { cookie: false });
io.on('connection', function(socket){
console.log('a user connected');
});
http.listen(3000, function(){
console.log('listening on *:3000');
}); Client: import socketio
sio = socketio.Client(logger=True)
sio.connect('http://localhost:3000', headers={'Cookie': 'some-cookie'})
print(sio.eio.http.cookies) |
I was able to work around this issue with the following code. s = requests.Session()
payload = {
'some-field': 'some-value'
}
s.post(URL, payload)
sio = socketio.Client(logger=True)
sio.eio.http = s
sio.connect(URL)
print(sio.eio.http.cookies) # contains cookies from the `s` and the HTTP transport response |
@jackdreinhardt if you have a moment and would like to test this fix I'd appreciate it. The solution that I implemented combines any cookies given in headers, with cookies that are already in the cookie jar. Please install the master branch of this package to test. Thanks. |
Hi,
I am working on a project in which I need to set up a websocket connection to an
express.js
app runningpassport.js
for authentication. I am running into an issue because the response headers from the initial polling request (e.g. the response fromhttp://localhost:8080/socket.io/?EIO=3&transport=polling&t=N0TyWKS
) contain aset-cookie
header, namelyio
, that needs to be added to the cookie list in the websocket request.The polling request is handled internally to the socket.io client
connect
function, so I am unable to add theio
cookie using the existing custom headers functionality. I am unable to change the configuration of the server, so support from the client side would be ideal.After taking a look at
_connect_polling()
inclient.py
, it seems like it would be pretty easy to scan the response headers forset-cookie
and add the cookies to the existing headers. Something like this would suffice:Not sure if this is the best solution, but it seems like it would work to me.
The text was updated successfully, but these errors were encountered: