Skip to content

Commit 691de0e

Browse files
committed
Fix for cross-domain websocket (fixes #42)
1 parent c9ec8e2 commit 691de0e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/socket.io/transports/websocket.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ WebSocket.prototype._onConnect = function(req, socket){
3030
this.draft = 76;
3131
}
3232

33-
var origin = this.request.headers.origin;
33+
var origin = this.request.headers.origin,
34+
location = (this.connection.secure ? 'wss' : 'ws') + '://' + this.request.headers.host + this.request.url;
3435

3536
if (this.draft == 76){
3637
headers = [
3738
'HTTP/1.1 101 WebSocket Protocol Handshake',
3839
'Upgrade: WebSocket',
3940
'Connection: Upgrade',
40-
'Sec-WebSocket-Origin: ' + (origin || 'null'),
41-
'Sec-WebSocket-Location: ' + origin.replace(/^http/, 'ws') + this.request.url
41+
'Sec-WebSocket-Origin: ' + origin,
42+
'Sec-WebSocket-Location: ' + location
4243
];
4344

4445
if ('sec-websocket-protocol' in this.request.headers){
@@ -50,7 +51,7 @@ WebSocket.prototype._onConnect = function(req, socket){
5051
'Upgrade: WebSocket',
5152
'Connection: Upgrade',
5253
'WebSocket-Origin: ' + origin,
53-
'WebSocket-Location: ' + origin.replace(/^http/, 'ws') + this.request.url
54+
'WebSocket-Location: ' + location
5455
];
5556

5657
try {

0 commit comments

Comments
 (0)