From d37e3ec8085b66dcb3b3d6c11bc73c5283756f04 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Wed, 26 Sep 2012 17:47:51 -0400 Subject: [PATCH] Enable use of 'xhr' transport in Node.js Normally, Socket.io chooses the "ideal" transport in Node.js: WebSockets. This behavior can lead to unrealistic stress test results because real-world loads will not be comprised of 100% WebSocket connections. The XHR transport itself is fully functional in Node. The transport check currently fails only because `location` is not defined in the global scope. By guarding the access of `global.location.protocol`, the `XHR.check` method can correctly return `true` in Node. Note that this will **not** change the default behavior in Node clients to choose the "best available" transport. It only enables the use of a fully-functional transport when requested. --- lib/transports/xhr.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/transports/xhr.js b/lib/transports/xhr.js index dab91f55d..06259055d 100644 --- a/lib/transports/xhr.js +++ b/lib/transports/xhr.js @@ -190,7 +190,7 @@ var request = io.util.request(xdomain), usesXDomReq = (global.XDomainRequest && request instanceof XDomainRequest), socketProtocol = (socket && socket.options && socket.options.secure ? 'https:' : 'http:'), - isXProtocol = (socketProtocol != global.location.protocol); + isXProtocol = (global.location && socketProtocol != global.location.protocol); if (request && !(usesXDomReq && isXProtocol)) { return true; }