mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
http: improve parser error messages
Include the library-provided reason in the Error’s `message`. Fixes: https://github.com/nodejs/node/issues/28468 PR-URL: https://github.com/nodejs/node/pull/28487 Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
1 parent
fd23c12263
commit
ba565a3734
8 files changed
+49
-6
No files matched your search
@@ -33,6 +33,7 @@ const {
|
||||
httpSocketSetup,
|
||||
parsers,
|
||||
HTTPParser,
|
||||
prepareError,
|
||||
} = require('_http_common');
|
||||
const { OutgoingMessage } = require('_http_outgoing');
|
||||
const Agent = require('_http_agent');
|
||||
@@ -451,6 +452,7 @@ function socketOnData(d) {
|
||||
|
||||
const ret = parser.execute(d);
|
||||
if (ret instanceof Error) {
|
||||
prepareError(ret, parser, d);
|
||||
debug('parse error', ret);
|
||||
freeParser(parser, req, socket);
|
||||
socket.destroy();
|
||||
|
||||
+8
-1
@@ -239,6 +239,12 @@ function cleanParser(parser) {
|
||||
parser._consumed = false;
|
||||
}
|
||||
|
||||
function prepareError(err, parser, rawPacket) {
|
||||
err.rawPacket = rawPacket || parser.getCurrentBuffer();
|
||||
if (typeof err.reason === 'string')
|
||||
err.message = `Parse Error: ${err.reason}`;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
_checkInvalidHeaderChar: checkInvalidHeaderChar,
|
||||
_checkIsHttpToken: checkIsHttpToken,
|
||||
@@ -251,5 +257,6 @@ module.exports = {
|
||||
methods,
|
||||
parsers,
|
||||
kIncomingMessage,
|
||||
HTTPParser
|
||||
HTTPParser,
|
||||
prepareError,
|
||||
};
|
||||
+3
-1
@@ -35,7 +35,8 @@ const {
|
||||
httpSocketSetup,
|
||||
kIncomingMessage,
|
||||
HTTPParser,
|
||||
_checkInvalidHeaderChar: checkInvalidHeaderChar
|
||||
_checkInvalidHeaderChar: checkInvalidHeaderChar,
|
||||
prepareError,
|
||||
} = require('_http_common');
|
||||
const { OutgoingMessage } = require('_http_outgoing');
|
||||
const { outHeadersKey, ondrain, nowDate } = require('internal/http');
|
||||
@@ -550,6 +551,7 @@ function onParserExecuteCommon(server, socket, parser, state, ret, d) {
|
||||
resetSocketTimeout(server, socket, state);
|
||||
|
||||
if (ret instanceof Error) {
|
||||
prepareError(ret, parser, d);
|
||||
ret.rawPacket = d || parser.getCurrentBuffer();
|
||||
debug('parse error', ret);
|
||||
socketOnError.call(socket, ret);
|
||||
|
||||
Reference in new issue
Block a user