1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6const assert = require('assert'); 7const http2 = require('http2'); 8 9{ 10 const testResBody = 'other stuff!\n'; 11 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. 15 16 const server = http2.createServer(); 17 18 let sentResponse = false; 19 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 = ''; 29 30 const client = http2.connect(`http://localhost:${server.address().port}`); 31 const req = client.request({ 32 ':method': 'POST', 33 'expect': '100-continue' 34 }); 35 36 let gotContinue = false; 37 req.on('continue', common.mustCall(() => { 38 gotContinue = true; 39 })); 40 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 })); 47 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 })); 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(); 63 64 server.on('request', common.mustCall((req, res) => { 65 res.end(); 66 })); 67 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 })); 94 })); 95} 96