|
3 | 3 | const { |
4 | 4 | mustCall, |
5 | 5 | mustNotCall, |
6 | | - expectsError, |
7 | 6 | hasCrypto, |
8 | 7 | skip |
9 | 8 | } = require('../common'); |
10 | 9 | if (!hasCrypto) |
11 | 10 | skip('missing crypto'); |
12 | 11 | const { createServer, connect } = require('http2'); |
13 | 12 | const assert = require('assert'); |
14 | | - |
15 | | -const server = createServer(); |
16 | | -server.listen(0, mustCall(() => { |
17 | | - const port = server.address().port; |
18 | | - const url = `http://localhost:${port}`; |
19 | | - const client = connect(url, mustCall(() => { |
20 | | - const request = client.request(); |
21 | | - request.resume(); |
22 | | - request.on('end', mustCall()); |
23 | | - request.on('close', mustCall(() => { |
24 | | - client.close(); |
| 13 | +{ |
| 14 | + const server = createServer(); |
| 15 | + server.listen(0, mustCall(() => { |
| 16 | + const port = server.address().port; |
| 17 | + const url = `http://localhost:${port}`; |
| 18 | + const client = connect(url, mustCall(() => { |
| 19 | + const request = client.request(); |
| 20 | + request.resume(); |
| 21 | + request.on('end', mustCall()); |
| 22 | + request.on('close', mustCall(() => { |
| 23 | + client.close(); |
| 24 | + })); |
25 | 25 | })); |
26 | | - })); |
27 | 26 |
|
28 | | - server.once('request', mustCall((request, response) => { |
29 | | - // response.write() returns true |
30 | | - assert(response.write('muahaha', 'utf8', mustCall())); |
| 27 | + server.once('request', mustCall((request, response) => { |
| 28 | + // response.write() returns true |
| 29 | + assert(response.write('muahaha', 'utf8', mustCall())); |
31 | 30 |
|
32 | | - response.stream.close(0, mustCall(() => { |
33 | | - response.on('error', mustNotCall()); |
| 31 | + response.stream.close(0, mustCall(() => { |
| 32 | + response.on('error', mustNotCall()); |
34 | 33 |
|
35 | | - // response.write() without cb returns error |
36 | | - expectsError( |
37 | | - () => { response.write('muahaha'); }, |
38 | | - { |
39 | | - type: Error, |
40 | | - code: 'ERR_HTTP2_INVALID_STREAM', |
41 | | - message: 'The stream has been destroyed' |
42 | | - } |
43 | | - ); |
| 34 | + // response.write() without cb returns error |
| 35 | + response.write('muahaha', mustCall((err) => { |
| 36 | + assert.strictEqual(err.code, 'ERR_HTTP2_INVALID_STREAM'); |
44 | 37 |
|
45 | | - // response.write() with cb returns falsy value |
46 | | - assert(!response.write('muahaha', mustCall())); |
| 38 | + // response.write() with cb returns falsy value |
| 39 | + assert(!response.write('muahaha', mustCall())); |
| 40 | + |
| 41 | + client.destroy(); |
| 42 | + server.close(); |
| 43 | + })); |
| 44 | + })); |
| 45 | + })); |
| 46 | + })); |
| 47 | +} |
| 48 | + |
| 49 | +{ |
| 50 | + // Http2ServerResponse.write ERR_STREAM_WRITE_AFTER_END |
| 51 | + const server = createServer(); |
| 52 | + server.listen(0, mustCall(() => { |
| 53 | + const port = server.address().port; |
| 54 | + const url = `http://localhost:${port}`; |
| 55 | + const client = connect(url, mustCall(() => { |
| 56 | + const request = client.request(); |
| 57 | + request.resume(); |
| 58 | + request.on('end', mustCall()); |
| 59 | + request.on('close', mustCall(() => { |
| 60 | + client.close(); |
| 61 | + })); |
| 62 | + })); |
47 | 63 |
|
48 | | - client.destroy(); |
49 | | - server.close(); |
| 64 | + server.once('request', mustCall((request, response) => { |
| 65 | + response.end(); |
| 66 | + response.write('asd', mustCall((err) => { |
| 67 | + assert.strictEqual(err.code, 'ERR_STREAM_WRITE_AFTER_END'); |
| 68 | + client.destroy(); |
| 69 | + server.close(); |
| 70 | + })); |
50 | 71 | })); |
51 | 72 | })); |
52 | | -})); |
| 73 | +} |
0 commit comments