@@ -6,49 +6,90 @@ if (!common.hasCrypto) |
6 | 6 | const assert = require('assert'); |
7 | 7 | const http2 = require('http2'); |
8 | 8 |
|
9 | | -const testResBody = 'other stuff!\n'; |
| 9 | +{ |
| 10 | + const testResBody = 'other stuff!\n'; |
10 | 11 |
|
11 | | -// Checks the full 100-continue flow from client sending 'expect: 100-continue' |
12 | | -// through server receiving it, sending back :status 100, writing the rest of |
13 | | -// the request to finally the client receiving to. |
| 12 | + // Checks the full 100-continue flow from client sending 'expect: 100-continue' |
| 13 | + // through server receiving it, sending back :status 100, writing the rest of |
| 14 | + // the request to finally the client receiving to. |
14 | 15 |
|
15 | | -const server = http2.createServer(); |
| 16 | + const server = http2.createServer(); |
16 | 17 |
|
17 | | -let sentResponse = false; |
| 18 | + let sentResponse = false; |
18 | 19 |
|
19 | | -server.on('request', common.mustCall((req, res) => { |
20 | | - res.end(testResBody); |
21 | | - sentResponse = true; |
22 | | -})); |
| 20 | + server.on('request', common.mustCall((req, res) => { |
| 21 | + res.end(testResBody); |
| 22 | + sentResponse = true; |
| 23 | + })); |
| 24 | + |
| 25 | + server.listen(0); |
| 26 | + |
| 27 | + server.on('listening', common.mustCall(() => { |
| 28 | + let body = ''; |
23 | 29 |
|
24 | | -server.listen(0); |
| 30 | + const client = http2.connect(`http://localhost:${server.address().port}`); |
| 31 | + const req = client.request({ |
| 32 | + ':method': 'POST', |
| 33 | + 'expect': '100-continue' |
| 34 | + }); |
25 | 35 |
|
26 | | -server.on('listening', common.mustCall(() => { |
27 | | - let body = ''; |
| 36 | + let gotContinue = false; |
| 37 | + req.on('continue', common.mustCall(() => { |
| 38 | + gotContinue = true; |
| 39 | + })); |
28 | 40 |
|
29 | | - const client = http2.connect(`http://localhost:${server.address().port}`); |
30 | | - const req = client.request({ |
31 | | - ':method': 'POST', |
32 | | - 'expect': '100-continue' |
33 | | - }); |
| 41 | + req.on('response', common.mustCall((headers) => { |
| 42 | + assert.strictEqual(gotContinue, true); |
| 43 | + assert.strictEqual(sentResponse, true); |
| 44 | + assert.strictEqual(headers[':status'], 200); |
| 45 | + req.end(); |
| 46 | + })); |
34 | 47 |
|
35 | | - let gotContinue = false; |
36 | | - req.on('continue', common.mustCall(() => { |
37 | | - gotContinue = true; |
| 48 | + req.setEncoding('utf8'); |
| 49 | + req.on('data', common.mustCall((chunk) => { body += chunk; })); |
| 50 | + req.on('end', common.mustCall(() => { |
| 51 | + assert.strictEqual(body, testResBody); |
| 52 | + client.close(); |
| 53 | + server.close(); |
| 54 | + })); |
38 | 55 | })); |
| 56 | +} |
| 57 | + |
| 58 | +{ |
| 59 | + // Checks the full 100-continue flow from client sending 'expect: 100-continue' |
| 60 | + // through server receiving it and ending the request. |
| 61 | + |
| 62 | + const server = http2.createServer(); |
39 | 63 |
|
40 | | - req.on('response', common.mustCall((headers) => { |
41 | | - assert.strictEqual(gotContinue, true); |
42 | | - assert.strictEqual(sentResponse, true); |
43 | | - assert.strictEqual(headers[':status'], 200); |
44 | | - req.end(); |
| 64 | + server.on('request', common.mustCall((req, res) => { |
| 65 | + res.end(); |
45 | 66 | })); |
46 | 67 |
|
47 | | - req.setEncoding('utf8'); |
48 | | - req.on('data', common.mustCall((chunk) => { body += chunk; })); |
49 | | - req.on('end', common.mustCall(() => { |
50 | | - assert.strictEqual(body, testResBody); |
51 | | - client.close(); |
52 | | - server.close(); |
| 68 | + server.listen(0); |
| 69 | + |
| 70 | + server.on('listening', common.mustCall(() => { |
| 71 | + const client = http2.connect(`http://localhost:${server.address().port}`); |
| 72 | + const req = client.request({ |
| 73 | + ':path': '/', |
| 74 | + 'expect': '100-continue' |
| 75 | + }); |
| 76 | + |
| 77 | + let gotContinue = false; |
| 78 | + req.on('continue', common.mustCall(() => { |
| 79 | + gotContinue = true; |
| 80 | + })); |
| 81 | + |
| 82 | + let gotResponse = false; |
| 83 | + req.on('response', common.mustCall(() => { |
| 84 | + gotResponse = true; |
| 85 | + })); |
| 86 | + |
| 87 | + req.setEncoding('utf8'); |
| 88 | + req.on('end', common.mustCall(() => { |
| 89 | + assert.strictEqual(gotContinue, true); |
| 90 | + assert.strictEqual(gotResponse, true); |
| 91 | + client.close(); |
| 92 | + server.close(); |
| 93 | + })); |
53 | 94 | })); |
54 | | -})); |
| 95 | +} |