11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciif (!common.hasCrypto) 51cb0ef41Sopenharmony_ci common.skip('missing crypto'); 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst http2 = require('http2'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci{ 101cb0ef41Sopenharmony_ci const testResBody = 'other stuff!\n'; 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci // Checks the full 100-continue flow from client sending 'expect: 100-continue' 131cb0ef41Sopenharmony_ci // through server receiving it, sending back :status 100, writing the rest of 141cb0ef41Sopenharmony_ci // the request to finally the client receiving to. 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci const server = http2.createServer(); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci let sentResponse = false; 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci server.on('request', common.mustCall((req, res) => { 211cb0ef41Sopenharmony_ci res.end(testResBody); 221cb0ef41Sopenharmony_ci sentResponse = true; 231cb0ef41Sopenharmony_ci })); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci server.listen(0); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci server.on('listening', common.mustCall(() => { 281cb0ef41Sopenharmony_ci let body = ''; 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci const client = http2.connect(`http://localhost:${server.address().port}`); 311cb0ef41Sopenharmony_ci const req = client.request({ 321cb0ef41Sopenharmony_ci ':method': 'POST', 331cb0ef41Sopenharmony_ci 'expect': '100-continue' 341cb0ef41Sopenharmony_ci }); 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci let gotContinue = false; 371cb0ef41Sopenharmony_ci req.on('continue', common.mustCall(() => { 381cb0ef41Sopenharmony_ci gotContinue = true; 391cb0ef41Sopenharmony_ci })); 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci req.on('response', common.mustCall((headers) => { 421cb0ef41Sopenharmony_ci assert.strictEqual(gotContinue, true); 431cb0ef41Sopenharmony_ci assert.strictEqual(sentResponse, true); 441cb0ef41Sopenharmony_ci assert.strictEqual(headers[':status'], 200); 451cb0ef41Sopenharmony_ci req.end(); 461cb0ef41Sopenharmony_ci })); 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci req.setEncoding('utf8'); 491cb0ef41Sopenharmony_ci req.on('data', common.mustCall((chunk) => { body += chunk; })); 501cb0ef41Sopenharmony_ci req.on('end', common.mustCall(() => { 511cb0ef41Sopenharmony_ci assert.strictEqual(body, testResBody); 521cb0ef41Sopenharmony_ci client.close(); 531cb0ef41Sopenharmony_ci server.close(); 541cb0ef41Sopenharmony_ci })); 551cb0ef41Sopenharmony_ci })); 561cb0ef41Sopenharmony_ci} 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ci{ 591cb0ef41Sopenharmony_ci // Checks the full 100-continue flow from client sending 'expect: 100-continue' 601cb0ef41Sopenharmony_ci // through server receiving it and ending the request. 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ci const server = http2.createServer(); 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ci server.on('request', common.mustCall((req, res) => { 651cb0ef41Sopenharmony_ci res.end(); 661cb0ef41Sopenharmony_ci })); 671cb0ef41Sopenharmony_ci 681cb0ef41Sopenharmony_ci server.listen(0); 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci server.on('listening', common.mustCall(() => { 711cb0ef41Sopenharmony_ci const client = http2.connect(`http://localhost:${server.address().port}`); 721cb0ef41Sopenharmony_ci const req = client.request({ 731cb0ef41Sopenharmony_ci ':path': '/', 741cb0ef41Sopenharmony_ci 'expect': '100-continue' 751cb0ef41Sopenharmony_ci }); 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ci let gotContinue = false; 781cb0ef41Sopenharmony_ci req.on('continue', common.mustCall(() => { 791cb0ef41Sopenharmony_ci gotContinue = true; 801cb0ef41Sopenharmony_ci })); 811cb0ef41Sopenharmony_ci 821cb0ef41Sopenharmony_ci let gotResponse = false; 831cb0ef41Sopenharmony_ci req.on('response', common.mustCall(() => { 841cb0ef41Sopenharmony_ci gotResponse = true; 851cb0ef41Sopenharmony_ci })); 861cb0ef41Sopenharmony_ci 871cb0ef41Sopenharmony_ci req.setEncoding('utf8'); 881cb0ef41Sopenharmony_ci req.on('end', common.mustCall(() => { 891cb0ef41Sopenharmony_ci assert.strictEqual(gotContinue, true); 901cb0ef41Sopenharmony_ci assert.strictEqual(gotResponse, true); 911cb0ef41Sopenharmony_ci client.close(); 921cb0ef41Sopenharmony_ci server.close(); 931cb0ef41Sopenharmony_ci })); 941cb0ef41Sopenharmony_ci })); 951cb0ef41Sopenharmony_ci} 96