| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,6 +47,7 @@ const { | |||
| 47 | 47 | HTTPParser, | |
| 48 | 48 | isLenient, | |
| 49 | 49 | prepareError, | |
| 50 | + kSkipPendingData, | ||
| 50 | 51 | } = require('_http_common'); | |
| 51 | 52 | const { | |
| 52 | 53 | kUniqueHeaders, | |
@@ -692,7 +693,14 @@ function parserOnIncomingClient(res, shouldKeepAlive) { | |||
| 692 | 693 | // We already have a response object, this means the server | |
| 693 | 694 | // sent a double response. | |
| 694 | 695 | socket.destroy(); | |
| 695 | - return 0; // No special treatment. | ||
| 696 | + if (socket.parser) { | ||
| 697 | + // https://github.com/nodejs/node/issues/60025 | ||
| 698 | + // Now, parser.incoming is pointed to the new IncomingMessage, | ||
| 699 | + // we need to rewrite it to the first one and skip all the pending IncomingMessage | ||
| 700 | + socket.parser.incoming = req.res; | ||
| 701 | + socket.parser.incoming[kSkipPendingData] = true; | ||
| 702 | + } | ||
| 703 | + return 0; | ||
| 696 | 704 | } | |
| 697 | 705 | req.res = res; | |
| 698 | 706 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,6 +41,7 @@ const { | |||
| 41 | 41 | } = incoming; | |
| 42 | 42 | ||
| 43 | 43 | const kIncomingMessage = Symbol('IncomingMessage'); | |
| 44 | + const kSkipPendingData = Symbol('SkipPendingData'); | ||
| 44 | 45 | const kOnMessageBegin = HTTPParser.kOnMessageBegin | 0; | |
| 45 | 46 | const kOnHeaders = HTTPParser.kOnHeaders | 0; | |
| 46 | 47 | const kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0; | |
@@ -126,7 +127,7 @@ function parserOnBody(b) { | |||
| 126 | 127 | const stream = this.incoming; | |
| 127 | 128 | ||
| 128 | 129 | // If the stream has already been removed, then drop it. | |
| 129 | - if (stream === null) | ||
| 130 | + if (stream === null || stream[kSkipPendingData]) | ||
| 130 | 131 | return; | |
| 131 | 132 | ||
| 132 | 133 | // Pretend this was the result of a stream._read call. | |
@@ -141,7 +142,7 @@ function parserOnMessageComplete() { | |||
| 141 | 142 | const parser = this; | |
| 142 | 143 | const stream = parser.incoming; | |
| 143 | 144 | ||
| 144 | - if (stream !== null) { | ||
| 145 | + if (stream !== null && !stream[kSkipPendingData]) { | ||
| 145 | 146 | stream.complete = true; | |
| 146 | 147 | // Emit any trailing headers. | |
| 147 | 148 | const headers = parser._headers; | |
@@ -310,4 +311,5 @@ module.exports = { | |||
| 310 | 311 | HTTPParser, | |
| 311 | 312 | isLenient, | |
| 312 | 313 | prepareError, | |
| 314 | + kSkipPendingData, | ||
| 313 | 315 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,44 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + // Flags: --expose-gc | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const http = require('http'); | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + const { onGC } = require('../common/gc'); | ||
| 7 | + | ||
| 8 | + function createServer() { | ||
| 9 | + const server = http.createServer(common.mustCall((req, res) => { | ||
| 10 | + res.setHeader('Content-Type', 'application/json'); | ||
| 11 | + res.end(JSON.stringify({ hello: 'world' })); | ||
| 12 | + req.socket.write('HTTP/1.1 400 Bad Request\r\n\r\n'); | ||
| 13 | + })); | ||
| 14 | + | ||
| 15 | + return new Promise((resolve) => { | ||
| 16 | + server.listen(0, common.mustCall(() => { | ||
| 17 | + resolve(server); | ||
| 18 | + })); | ||
| 19 | + }); | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + async function main() { | ||
| 23 | + const server = await createServer(); | ||
| 24 | + const req = http.get({ | ||
| 25 | + port: server.address().port, | ||
| 26 | + }, common.mustCall((res) => { | ||
| 27 | + const chunks = []; | ||
| 28 | + res.on('data', common.mustCallAtLeast((c) => chunks.push(c), 1)); | ||
| 29 | + res.on('end', common.mustCall(() => { | ||
| 30 | + const body = Buffer.concat(chunks).toString('utf8'); | ||
| 31 | + const data = JSON.parse(body); | ||
| 32 | + assert.strictEqual(data.hello, 'world'); | ||
| 33 | + })); | ||
| 34 | + })); | ||
| 35 | + const timer = setInterval(global.gc, 300); | ||
| 36 | + onGC(req, { | ||
| 37 | + ongc: common.mustCall(() => { | ||
| 38 | + clearInterval(timer); | ||
| 39 | + server.close(); | ||
| 40 | + }) | ||
| 41 | + }); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + main(); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments