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.

PR-URL: #20029
Fixes: #19231
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Khaidi Chu <[email protected]>
  • Loading branch information
apapirovski committed Apr 17, 2018
1 parent 4f2000f commit 95fafc0
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 95fafc0

Please sign in to comment.