Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Enable use of 'xhr' transport in Node.js #471

Merged
merged 1 commit into from

3 participants

@jugglinmike

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.

@jugglinmike jugglinmike 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.
d37e3ec
@alvinsw

Please accept this commit. This is very important in enabling a long polling scheme between node servers that are proxied behind nginx. As we all know, current version of nginx does not support websockets.

@rauchg rauchg merged commit 2d9ffc3 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 26, 2012
  1. @jugglinmike

    Enable use of 'xhr' transport in Node.js

    jugglinmike authored
    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.
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  lib/transports/xhr.js
View
2  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;
}
Something went wrong with that request. Please try again.