diff --git a/lib/modem.js b/lib/modem.js index 6e60587..03d2ac3 100644 --- a/lib/modem.js +++ b/lib/modem.js @@ -227,7 +227,7 @@ Modem.prototype.dial = function (options, callback) { if (options.hijack) { optionsf.headers.Connection = 'Upgrade'; - optionsf.headers.Upgrade = 'tcp'; + optionsf.headers.Upgrade = optionsf.headers.Upgrade ?? 'tcp'; } if (this.socketPath) { @@ -302,6 +302,9 @@ Modem.prototype.buildRequest = function (options, context, data, callback) { req.on('upgrade', function (res, sock, head) { if (finished === false) { finished = true; + if (head.length > 0) { + sock.unshift(head); + } return callback(null, sock); } }); @@ -366,7 +369,7 @@ Modem.prototype.buildRequest = function (options, context, data, callback) { data.pipe(req); } - if (!context.hijack && !context.openStdin && (typeof data === 'string' || data === undefined || Buffer.isBuffer(data))) { + if (!context.openStdin && (typeof data === 'string' || data === undefined || Buffer.isBuffer(data))) { req.end(); } };