diff --git a/lib/goldilocks.js b/lib/goldilocks.js index 732678b..a0b3fcc 100644 --- a/lib/goldilocks.js +++ b/lib/goldilocks.js @@ -50,7 +50,7 @@ module.exports.create = function (deps, config) { } console.warn('failed to identify protocol from first chunk', firstChunk); - conn.close(); + conn.destroy(); } function netHandler(conn, opts) { function getProp(name) { diff --git a/lib/modules/http.js b/lib/modules/http.js index 048d3ac..636b6bc 100644 --- a/lib/modules/http.js +++ b/lib/modules/http.js @@ -29,12 +29,14 @@ module.exports.create = function (deps, conf, greenlockMiddleware) { function handleChunk(chunk) { if (!errored) { opts.firstChunk = Buffer.concat([opts.firstChunk, chunk]); - if (opts.firstChunk.includes('\r\n\r\n')) { - resolve(opts.firstChunk.toString()); - conn.removeListener('error', handleErr); - } else { + if (!opts.firstChunk.includes('\r\n\r\n')) { conn.once('data', handleChunk); + return; } + + conn.removeListener('error', handleErr); + conn.pause(); + resolve(opts.firstChunk.toString()); } } conn.once('data', handleChunk); @@ -144,6 +146,7 @@ module.exports.create = function (deps, conf, greenlockMiddleware) { // data comes in. process.nextTick(function () { conn.unshift(opts.firstChunk); + conn.resume(); }); // Convenience return for all the check* functions. @@ -160,6 +163,7 @@ module.exports.create = function (deps, conf, greenlockMiddleware) { deps.tunnelServer.handleClientConn(conn); process.nextTick(function () { conn.unshift(opts.firstChunk); + conn.resume(); }); return true; } @@ -211,6 +215,7 @@ module.exports.create = function (deps, conf, greenlockMiddleware) { deps.tunnelServer.handleAdminConn(conn); process.nextTick(function () { conn.unshift(opts.firstChunk); + conn.resume(); }); return true; }