I'm using verifyClient, with session like this:
verifyClient(info, cb) {
sessionParser(info.req, {}, function () {
logger.info(info.req.session,'Session info');
if (info.req.session) //check session
{
return cb(true);
}
else {
//authenticate here
}
}
The session cookie is not sent to the client, so I tried to add
info.req.headers["set-cookie"] = info.req.session.SessionID;
in verifyClient after auth
but that doesn't help.
the only place the cookie is sent is if I set it in the
wsServer.on('headers', function(headers) {
headers.push("set-cookie: mycookie=12345632");
}
but i can't access the session from there, so I can't grab the SessionID in that function.
So how would I go about sending that cookie to the client?
Thanks
seems like the problem is I get access to the request in verifyClient, but not the response; so I can't set a response header, Meanwhile in the on('headers') event, it's only the headers that are exposed, not the request or response.
Is there any way around this?
Thanks
+1
So if you are looking to fail the client, you can use my PR: https://github.com/websockets/ws/pull/801 and return the headers on a failure, but I am not sure that is what you are looking for... Just trying to be helpful...
@mkamioner thanks for the note and the PR:
It seems like your PR only send headers on failure... so it's note really what I want.
I want to send headers with the response, whether it is a failure or not, so i can set a cookie on the client side, to be used for reconnection (should the connection be closed for some reason).
Just like a session cookie is used for standard HTTP connections.
I just took another stab at it - Let me know what you think (https://github.com/websockets/ws/pull/801)
This is great feature. Please update typings (TS) repository as well.
Most helpful comment
This is great feature. Please update typings (TS) repository as well.