|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const assert = require('assert'); |
| 4 | +const http2 = require('http2'); |
| 5 | + |
| 6 | +const common = require('../common'); |
| 7 | +if (!common.hasCrypto) |
| 8 | + common.skip('missing crypto'); |
| 9 | + |
| 10 | +for (const chunkSequence of [ |
| 11 | + [ '' ], |
| 12 | + [ '', '' ] |
| 13 | +]) { |
| 14 | + const server = http2.createServer(); |
| 15 | + server.on('stream', common.mustCall((stream, headers, flags) => { |
| 16 | + stream.respond({ 'content-type': 'text/html' }); |
| 17 | + |
| 18 | + let data = ''; |
| 19 | + stream.on('data', common.mustNotCall((chunk) => { |
| 20 | + data += chunk.toString(); |
| 21 | + })); |
| 22 | + stream.on('end', common.mustCall(() => { |
| 23 | + stream.end(`"${data}"`); |
| 24 | + })); |
| 25 | + })); |
| 26 | + |
| 27 | + server.listen(0, common.mustCall(() => { |
| 28 | + const port = server.address().port; |
| 29 | + const client = http2.connect(`http://localhost:${port}`); |
| 30 | + |
| 31 | + const req = client.request({ |
| 32 | + ':method': 'POST', |
| 33 | + ':path': '/' |
| 34 | + }); |
| 35 | + |
| 36 | + req.on('response', common.mustCall((headers) => { |
| 37 | + assert.strictEqual(headers[':status'], 200); |
| 38 | + assert.strictEqual(headers['content-type'], 'text/html'); |
| 39 | + })); |
| 40 | + |
| 41 | + let data = ''; |
| 42 | + req.setEncoding('utf8'); |
| 43 | + req.on('data', common.mustCallAtLeast((d) => data += d)); |
| 44 | + req.on('end', common.mustCall(() => { |
| 45 | + assert.strictEqual(data, '""'); |
| 46 | + server.close(); |
| 47 | + client.close(); |
| 48 | + })); |
| 49 | + |
| 50 | + for (const chunk of chunkSequence) |
| 51 | + req.write(chunk); |
| 52 | + req.end(); |
| 53 | + })); |
| 54 | +} |
0 commit comments