-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http2: fix stream reading resumption
_read should always resume the underlying code that is attempting to push data to a readable stream. Adjust http2 core code to resume its reading appropriately. Some other general cleanup around reading, resuming & draining. PR-URL: #16580 Fixes: #16578 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
1 parent
528edb2
commit 95a61cb
Showing
7 changed files
with
79 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
const fixtures = require('../common/fixtures'); | ||
const assert = require('assert'); | ||
const http2 = require('http2'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
// piping should work as expected with createWriteStream | ||
|
||
common.refreshTmpDir(); | ||
const loc = fixtures.path('url-tests.js'); | ||
const fn = path.join(common.tmpDir, 'http2-url-tests.js'); | ||
|
||
const server = http2.createServer(); | ||
|
||
server.on('stream', common.mustCall((stream) => { | ||
const dest = stream.pipe(fs.createWriteStream(fn)); | ||
dest.on('finish', common.mustCall(() => { | ||
assert.strictEqual(fs.readFileSync(loc).length, fs.readFileSync(fn).length); | ||
fs.unlinkSync(fn); | ||
stream.respond(); | ||
stream.end(); | ||
})); | ||
})); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const port = server.address().port; | ||
const client = http2.connect(`http://localhost:${port}`); | ||
|
||
let remaining = 2; | ||
function maybeClose() { | ||
if (--remaining === 0) { | ||
server.close(); | ||
client.destroy(); | ||
} | ||
} | ||
|
||
const req = client.request({ ':method': 'POST' }); | ||
req.on('response', common.mustCall()); | ||
req.resume(); | ||
req.on('end', common.mustCall(maybeClose)); | ||
const str = fs.createReadStream(loc); | ||
str.on('end', common.mustCall(maybeClose)); | ||
str.pipe(req); | ||
})); |