Handshake data flush bug #289

Closed
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+7 −4
Diff settings

Always

Just for now

@@ -607,6 +607,7 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
// connections.
//
function proxyError (err) {
+ console.log('proxy error', err);
reverseProxy.destroy();
process.nextTick(function () {
@@ -669,23 +670,25 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
sdata = sdata.substr(0, sdata.search(CRLF + CRLF));
// Get the Non-Printable data
- data = data.slice(Buffer.byteLength(sdata), data.length);
+ var bdata = data.slice(Buffer.byteLength(sdata), data.length);
if (self.source.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:');
+ data = new Buffer(Buffer.byteLength(sdata)+bdata.length);
+ data.write(sdata, 0, Buffer.byteLength(sdata), 'utf8');
+ bdata.copy(data, Buffer.byteLength(sdata), 0, bdata.length);
}
try {
//
// Write the printable and non-printable data to the socket
// from the original incoming request.
//
- self.emit('websocket:handshake', req, socket, head, sdata, data);
- socket.write(sdata);
+ self.emit('websocket:handshake', req, socket, head, data, data);
var flushed = socket.write(data);
if (!flushed) {
revSocket.pause();
@@ -700,7 +703,7 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
//
setTimeout(function () {
socket.emit('drain');
- }, 100);
+ }, 700);
}
}
catch (ex) {