Skip to content

Commit

Permalink
http: fix undefined error in parser event
Browse files Browse the repository at this point in the history
The current check for socket.server[kIncomingMessage] does not
account for the possibility of a socket.server that doesn't
have that property defined. Fix it.

Backport-PR-URL: #22880
PR-URL: #20029
Fixes: #19231
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Khaidi Chu <i@2333.moe>
  • Loading branch information
apapirovski authored and MylesBorins committed Oct 31, 2018
1 parent ce65d84 commit e3bddee
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/_http_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ function parserOnHeaders(headers, url) {
function parserOnHeadersComplete(versionMajor, versionMinor, headers, method,
url, statusCode, statusMessage, upgrade,
shouldKeepAlive) {
var parser = this;
const parser = this;
const { socket } = parser;

if (!headers) {
headers = parser._headers;
Expand All @@ -75,10 +76,11 @@ function parserOnHeadersComplete(versionMajor, versionMinor, headers, method,
}

// Parser is also used by http client
var ParserIncomingMessage = parser.socket && parser.socket.server ?
parser.socket.server[kIncomingMessage] : IncomingMessage;
const ParserIncomingMessage = (socket && socket.server &&
socket.server[kIncomingMessage]) ||
IncomingMessage;

parser.incoming = new ParserIncomingMessage(parser.socket);
parser.incoming = new ParserIncomingMessage(socket);
parser.incoming.httpVersionMajor = versionMajor;
parser.incoming.httpVersionMinor = versionMinor;
parser.incoming.httpVersion = `${versionMajor}.${versionMinor}`;
Expand Down

0 comments on commit e3bddee

Please sign in to comment.