mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[fix] Change sec-websocket-location header when proxying WSS --> WS. Added test coverage for this scenario
This commit is contained in:
parent
76ecb51e7b
commit
028d2044e7
@ -222,6 +222,7 @@ var HttpProxy = exports.HttpProxy = function (options) {
|
|||||||
options = options || {};
|
options = options || {};
|
||||||
options.target = options.target || {};
|
options.target = options.target || {};
|
||||||
|
|
||||||
|
this.https = options.https;
|
||||||
this.forward = options.forward;
|
this.forward = options.forward;
|
||||||
this.target = options.target;
|
this.target = options.target;
|
||||||
this.changeOrigin = options.changeOrigin || false;
|
this.changeOrigin = options.changeOrigin || false;
|
||||||
@ -706,10 +707,20 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
|
|||||||
// Get the Non-Printable data
|
// Get the Non-Printable data
|
||||||
data = data.slice(Buffer.byteLength(sdata), data.length);
|
data = data.slice(Buffer.byteLength(sdata), data.length);
|
||||||
|
|
||||||
|
//
|
||||||
// Replace the host and origin headers in the Printable data
|
// Replace the host and origin headers in the Printable data
|
||||||
|
//
|
||||||
sdata = sdata.replace(remoteHost, options.host)
|
sdata = sdata.replace(remoteHost, options.host)
|
||||||
.replace(remoteHost, options.host);
|
.replace(remoteHost, options.host);
|
||||||
|
|
||||||
|
if (self.https && !self.target.https) {
|
||||||
|
//
|
||||||
|
// If the proxy server is running HTTPS but the client is running
|
||||||
|
// HTTP then replace `ws` with `wss` in the data sent back to the client.
|
||||||
|
//
|
||||||
|
sdata = sdata.replace('ws:', 'wss:');
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//
|
//
|
||||||
// Write the printable and non-printable data to the socket
|
// Write the printable and non-printable data to the socket
|
||||||
|
|||||||
@ -87,6 +87,8 @@ vows.describe('node-http-proxy/websocket/' + wsprotocol).addBatch({
|
|||||||
assert.equal(msg, 'from client');
|
assert.equal(msg, 'from client');
|
||||||
},
|
},
|
||||||
"the origin and sec-websocket-origin headers should match": function (err, msg, headers) {
|
"the origin and sec-websocket-origin headers should match": function (err, msg, headers) {
|
||||||
|
assert.isString(headers.response['sec-websocket-location']);
|
||||||
|
assert.isTrue(headers.response['sec-websocket-location'].indexOf(wsprotocol) !== -1);
|
||||||
assert.equal(headers.request.Origin, headers.response['sec-websocket-origin']);
|
assert.equal(headers.request.Origin, headers.response['sec-websocket-origin']);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -128,6 +130,8 @@ vows.describe('node-http-proxy/websocket/' + wsprotocol).addBatch({
|
|||||||
assert.equal(msg, 'from server');
|
assert.equal(msg, 'from server');
|
||||||
},
|
},
|
||||||
"the origin and sec-websocket-origin headers should match": function (err, msg, headers) {
|
"the origin and sec-websocket-origin headers should match": function (err, msg, headers) {
|
||||||
|
assert.isString(headers.response['sec-websocket-location']);
|
||||||
|
assert.isTrue(headers.response['sec-websocket-location'].indexOf(wsprotocol) !== -1);
|
||||||
assert.equal(headers.request.Origin, headers.response['sec-websocket-origin']);
|
assert.equal(headers.request.Origin, headers.response['sec-websocket-origin']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user