From b4ac4d441fe4fb84d463bd889a5ce8d7f4d596ca Mon Sep 17 00:00:00 2001
From: indexzero
var sdata = data.toString();Get the Printable data
sdata = sdata.substr(0, sdata.search(CRLF + CRLF));Get the Non-Printable data
data = data.slice(Buffer.byteLength(sdata), data.length);Replace the host and origin headers in the Printable data
sdata = sdata.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 {Write the printable and non-printable data to the socket + try {
Write the printable and non-printable data to the socket from the original incoming request.
socket.write(sdata);
socket.write(data);
}
catch (ex) {
proxyError(ex)
- }Catch socket errors
socket.on('error', proxyError);Remove data listener now that the 'handshake' is complete
reverseProxy.socket.removeListener('data', handshake);
+ }Catch socket errors
socket.on('error', proxyError);Remove data listener now that the 'handshake' is complete
reverseProxy.socket.removeListener('data', handshake);
});
}
reverseProxy.on('error', proxyError);
- try {Attempt to write the upgrade-head to the reverseProxy request.
reverseProxy.write(head);
+ try {Attempt to write the upgrade-head to the reverseProxy request.
reverseProxy.write(head);
}
catch (ex) {
proxyError(ex);
}
- If we have been passed buffered data, resume it.
if (options.buffer && !errState) {
+ If we have been passed buffered data, resume it.
if (options.buffer && !errState) {
options.buffer.resume();
}
};