Skip to content

Commit

Permalink
Adding configuration variable matchOriginProtocol
Browse files Browse the repository at this point in the history
matchOriginProtocol is meant to be used when running socket.io behind a
proxy. matchOriginProtocol should be set to true when you want the
location handshake to match the protocol of the origin. This fixes
issues with terminating the SSL in front of Node and forcing location
to think it's wss instead of ws.
  • Loading branch information
mattrobenolt committed Nov 3, 2011
1 parent 220f8d5 commit 6f2270a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function Manager (server, options) {
, 'browser client gzip': false
, 'browser client handler': false
, 'client store expiration': 15
, matchOriginProtocol: false
};

for (var i in options) {
Expand Down
5 changes: 4 additions & 1 deletion lib/transports/websocket/default.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*!
* socket.io-node
* Copyright(c) 2011 LearnBoost <[email protected]>
Expand Down Expand Up @@ -88,7 +89,9 @@ WebSocket.prototype.onSocketConnect = function () {
}

var origin = this.req.headers.origin
, location = (origin.match(/^https/) ? 'wss' : 'ws')
, location = ((this.manager.settings.matchOriginProtocol ?
origin.match(/^https/) : this.socket.encrypted) ?
'wss' : 'ws')
+ '://' + this.req.headers.host + this.req.url
, waitingForNonce = false;

Expand Down
4 changes: 3 additions & 1 deletion lib/transports/websocket/hybi-07-12.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ WebSocket.prototype.onSocketConnect = function () {
}

var origin = this.req.headers['sec-websocket-origin']
, location = (this.socket.encrypted ? 'wss' : 'ws')
, location = ((this.manager.settings.matchOriginProtocol ?
origin.match(/^https/) : this.socket.encrypted) ?
'wss' : 'ws')
+ '://' + this.req.headers.host + this.req.url;

if (!this.verifyOrigin(origin)) {
Expand Down
4 changes: 3 additions & 1 deletion lib/transports/websocket/hybi-16.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ WebSocket.prototype.onSocketConnect = function () {
}

var origin = this.req.headers['origin']
, location = (this.socket.encrypted ? 'wss' : 'ws')
, location = ((this.manager.settings.matchOriginProtocol ?
origin.match(/^https/) : this.socket.encrypted) ?
'wss' : 'ws')
+ '://' + this.req.headers.host + this.req.url;

if (!this.verifyOrigin(origin)) {
Expand Down

0 comments on commit 6f2270a

Please sign in to comment.