Skip to content

Commit c023fae

Browse files
committed
Updated client
Fixed WebSocket location header for ws/wss (Thanks @jdub, Fixes #40)
1 parent 39bc175 commit c023fae

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

example/client

Submodule client updated from 4697574 to 41ad405

lib/socket.io/transports/websocket.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,28 @@ WebSocket.prototype._onConnect = function(req, socket){
2929
if ('sec-websocket-key1' in this.request.headers){
3030
this.draft = 76;
3131
}
32-
33-
if (this.draft == 76){
34-
var origin = this.request.headers.origin;
32+
33+
var origin = this.request.headers.origin;
3534

35+
if (this.draft == 76){
3636
headers = [
3737
'HTTP/1.1 101 WebSocket Protocol Handshake',
3838
'Upgrade: WebSocket',
3939
'Connection: Upgrade',
4040
'Sec-WebSocket-Origin: ' + (origin || 'null'),
41-
'Sec-WebSocket-Location: ws://' + this.request.headers.host + this.request.url
41+
'Sec-WebSocket-Location: ' + origin.replace(/^http/, 'ws') + this.request.url
4242
];
4343

4444
if ('sec-websocket-protocol' in this.request.headers){
4545
headers.push('Sec-WebSocket-Protocol: ' + this.request.headers['sec-websocket-protocol']);
4646
}
4747
} else {
48-
4948
headers = [
5049
'HTTP/1.1 101 Web Socket Protocol Handshake',
5150
'Upgrade: WebSocket',
5251
'Connection: Upgrade',
53-
'WebSocket-Origin: ' + this.request.headers.origin,
54-
'WebSocket-Location: ws://' + this.request.headers.host + this.request.url
52+
'WebSocket-Origin: ' + origin,
53+
'WebSocket-Location: ' + origin.replace(/^http/, 'ws') + this.request.url
5554
];
5655

5756
try {

0 commit comments

Comments
 (0)