简体   繁体   English

node.js socket.io-client是否应该处理set-cookie

[英]Is node.js socket.io-client supposed to handle set-cookie

Is the node.js socket.io-client supposed to automatically handle cookies? node.js socket.io-client是否应该自动处理cookie? That is, for all Set-Cookie response headers, is it supposed to pass back the corresponding Cookie headers during the handshake? 也就是说,对于所有Set-Cookie响应标头,是否应该在握手期间传递回相应的Cookie标头?

The reason I'm asking is because I have a proxy (the cloud foundry gorouter) between my client and 3 server instances. 我问的原因是因为我在客户端和3个服务器实例之间有一个代理(云代工厂gorouter)。 The socket.io server is appropriately setting two cookies (JSESSIONID and VCAP_ID ) on the response and I need the client to send them back appropriately so that affinity is kept by the gorouter. socket.io服务器在响应上适当地设置了两个cookie(JSESSIONID和VCAP_ID ),我需要客户端适当地将它们发送回去,以便gorouter保持亲和力。 I am currently getting connect failures due to a "transport error" when multiple instances of the server are running, but the problem goes away when I have a single server instance running. 当前正在运行多个服务器实例时由于“传输错误”而导致连接失败,但是当我运行单个服务器实例时问题就消失了。

Thanks in advance, Keith 预先感谢,基思

If you want to access cookies in socket.io check out the following. 如果要访问socket.io中的cookie,请检查以下内容。

http://socket.io/docs/server-api/#namespace#use(fn:function):namespace http://socket.io/docs/server-api/#namespace#use(fn:function):namespace

var io = require('socket.io')();
io.on('connection', function(socket){
  socket.to('others').emit('an event', { some: 'data' });
});

Additionally check out this post on how to do authentication in socket. 此外,请查看有关如何在套接字中进行身份验证的文章。 Socket.IO Authentication Socket.IO身份验证

Yes, I did get it to work, but the only node module I could get to work at the time was 'ws' as follows: 是的,我确实可以使用它,但是当时唯一可以使用的节点模块是“ ws”,如下所示:

var WebSocket = require('ws');
var webSocketUrl = ""wss://" + ...
var opts = { headers: { Cookie: 'JSESSIONID=1; __VCAP_ID__='+vcapID} };
var socket = new WebSocket(websocketUrl,opts);

-- Keith -基思

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM