Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
http: add rawPacket in err of `clientError` event #17672
Conversation
XadillaX
referenced this pull request
in eggjs/egg
Dec 14, 2017
Merged
feat: add 400 response for broken client request to instead of empty response #1829
jasnell
added
semver-minor
http
labels
Dec 14, 2017
| @@ -765,6 +765,11 @@ object, so any HTTP response sent, including response headers and payload, | ||
| *must* be written directly to the `socket` object. Care must be taken to | ||
| ensure the response is a properly formatted HTTP response message. | ||
| +> `err` is an instance of `Error` with two extra columns: |
| @@ -765,6 +765,11 @@ object, so any HTTP response sent, including response headers and payload, | ||
| *must* be written directly to the `socket` object. Care must be taken to | ||
| ensure the response is a properly formatted HTTP response message. | ||
| +> `err` is an instance of `Error` with two extra columns: | ||
| +> | ||
| +> + `bytesParsed`: the bytes count of request packet that Node.js may parse correctly; |
XadillaX
Dec 15, 2017
Member
It's the count of 'correctly', not 'incorrectly'. Means Node.js have parsed bytesParsed correctly and the left are incorrectly.
| @@ -476,6 +476,7 @@ function onParserExecuteCommon(server, socket, parser, state, ret, d) { | ||
| resetSocketTimeout(server, socket, state); | ||
| if (ret instanceof Error) { | ||
| + ret.rawPacket = d || parser.getCurrentBuffer(); |
addaleax
Dec 14, 2017
Owner
I'm not sure, but can you maybe move the
if (!d)
d = parser.getCurrentBuffer();block in front of the if (ret instanceof Error) part? Then you can always just use d inside of this function
|
@addaleax I've updated the code |
| +`err` is an instance of `Error` with two extra columns: | ||
| + | ||
| ++ `bytesParsed`: the bytes count of request packet that Node.js may have parsed correctly; | ||
| ++ `rawPacket`: the raw packet of current request. |
addaleax
Dec 15, 2017
Owner
Sorry, one thing I forgot to mention: Can you list the addition of rawPacket in the changes: section of the YAML block for clientError?
| @@ -475,7 +475,11 @@ function socketOnError(e) { | ||
| function onParserExecuteCommon(server, socket, parser, state, ret, d) { | ||
| resetSocketTimeout(server, socket, state); | ||
| + if (!d) | ||
| + d = parser.getCurrentBuffer(); |
bnoordhuis
Dec 15, 2017
Member
Can you move this into the branches of the if statement? parser.getCurrrentBuffer() creates a copy. Calling it when the result is unused is wasteful and probably has a pretty big performance impact.
XadillaX
Dec 15, 2017
Member
But if we don't get the buffer, we cannot pass it to the clientError event.
XadillaX
added
the
lts-watch-v6.x
label
Dec 15, 2017
|
/ping @addaleax @bnoordhuis |
| @@ -734,6 +734,11 @@ changes: | ||
| description: The default action of calling `.destroy()` on the `socket` | ||
| will no longer take place if there are listeners attached | ||
| for `clientError`. | ||
| + - version: VERSION |
| @@ -475,7 +475,12 @@ function socketOnError(e) { | ||
| function onParserExecuteCommon(server, socket, parser, state, ret, d) { | ||
| resetSocketTimeout(server, socket, state); | ||
| + if (!d) { | ||
| + d = parser.getCurrentBuffer(); | ||
| + } |
addaleax
Dec 18, 2017
Owner
I think @bnoordhuis’ comment was basically about undoing my earlier comment (which is probably better, yes). i.e. move this part back into the branches were d is actually used, not before the if
|
/ping @addaleax @bnoordhuis |
XadillaX
added
the
lts-watch-v8.x
label
Dec 20, 2017
addaleax
added
the
ready
label
Dec 20, 2017
| @@ -765,6 +770,11 @@ object, so any HTTP response sent, including response headers and payload, | ||
| *must* be written directly to the `socket` object. Care must be taken to | ||
| ensure the response is a properly formatted HTTP response message. | ||
| +`err` is an instance of `Error` with two extra columns: | ||
| + | ||
| ++ `bytesParsed`: the bytes count of request packet that Node.js may have parsed correctly; |
XadillaX commentedDec 14, 2017
•
Edited 4 times
-
XadillaX
Dec 14, 2017
-
XadillaX
Dec 14, 2017
-
XadillaX
Dec 14, 2017
-
XadillaX
Dec 14, 2017
The
rawPacketis the current buffer that just parsed. Adding thisbuffer to the error object of
clientErrorevent is to make it possiblethat developers can log the broken packet.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
http