|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +if (!common.hasCrypto) |
| 5 | + common.skip('missing crypto'); |
| 6 | +const fixtures = require('../common/fixtures'); |
| 7 | +const assert = require('assert'); |
| 8 | +const http2 = require('http2'); |
| 9 | +const fs = require('fs'); |
| 10 | +const path = require('path'); |
| 11 | + |
| 12 | +// piping should work as expected with createWriteStream |
| 13 | + |
| 14 | +const loc = fixtures.path('url-tests.js'); |
| 15 | +const fn = path.join(common.tmpDir, 'http2-url-tests.js'); |
| 16 | +common.refreshTmpDir(); |
| 17 | + |
| 18 | +const server = http2.createServer(); |
| 19 | + |
| 20 | +server.on('stream', common.mustCall((stream) => { |
| 21 | + const dest = stream.pipe(fs.createWriteStream(fn)); |
| 22 | + dest.on('finish', common.mustCall(() => { |
| 23 | + assert.deepStrictEqual(fs.readFileSync(loc), fs.readFileSync(fn)); |
| 24 | + fs.unlinkSync(fn); |
| 25 | + stream.respond(); |
| 26 | + stream.end(); |
| 27 | + })); |
| 28 | +})); |
| 29 | + |
| 30 | +server.listen(0, common.mustCall(() => { |
| 31 | + const port = server.address().port; |
| 32 | + const client = http2.connect(`http://localhost:${port}`); |
| 33 | + |
| 34 | + let remaining = 2; |
| 35 | + function maybeClose() { |
| 36 | + if (--remaining === 0) { |
| 37 | + server.close(); |
| 38 | + client.destroy(); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + const req = client.request({ ':method': 'POST' }); |
| 43 | + req.on('response', common.mustCall()); |
| 44 | + req.resume(); |
| 45 | + req.on('end', common.mustCall(maybeClose)); |
| 46 | + const str = fs.createReadStream(loc); |
| 47 | + str.on('end', common.mustCall(maybeClose)); |
| 48 | + str.pipe(req); |
| 49 | +})); |
0 commit comments