11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciif (!common.hasCrypto) 61cb0ef41Sopenharmony_ci common.skip('missing crypto'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst assert = require('assert'); 91cb0ef41Sopenharmony_ciconst https = require('https'); 101cb0ef41Sopenharmony_ciconst debug = require('util').debuglog('test'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_cilet counter = 0; 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciconst httpsServer = https.createServer({ 151cb0ef41Sopenharmony_ci key: fixtures.readKey('agent1-key.pem'), 161cb0ef41Sopenharmony_ci cert: fixtures.readKey('agent1-cert.pem'), 171cb0ef41Sopenharmony_ci}, common.mustCall(function(req, res) { 181cb0ef41Sopenharmony_ci debug(`Got request: ${req.headers.host} ${req.url}`); 191cb0ef41Sopenharmony_ci if (req.url.startsWith('/setHostFalse')) { 201cb0ef41Sopenharmony_ci assert.strictEqual(req.headers.host, undefined); 211cb0ef41Sopenharmony_ci } else { 221cb0ef41Sopenharmony_ci assert.strictEqual( 231cb0ef41Sopenharmony_ci req.headers.host, `localhost:${this.address().port}`, 241cb0ef41Sopenharmony_ci `Wrong host header for req[${req.url}]: ${req.headers.host}`); 251cb0ef41Sopenharmony_ci } 261cb0ef41Sopenharmony_ci res.writeHead(200, {}); 271cb0ef41Sopenharmony_ci res.end('ok'); 281cb0ef41Sopenharmony_ci}, 9)).listen(0, common.mustCall(function(err) { 291cb0ef41Sopenharmony_ci debug(`test https server listening on port ${this.address().port}`); 301cb0ef41Sopenharmony_ci assert.ifError(err); 311cb0ef41Sopenharmony_ci https.get({ 321cb0ef41Sopenharmony_ci method: 'GET', 331cb0ef41Sopenharmony_ci path: `/${counter++}`, 341cb0ef41Sopenharmony_ci host: 'localhost', 351cb0ef41Sopenharmony_ci port: this.address().port, 361cb0ef41Sopenharmony_ci rejectUnauthorized: false, 371cb0ef41Sopenharmony_ci }, cb).on('error', common.mustNotCall()); 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci https.request({ 401cb0ef41Sopenharmony_ci method: 'GET', 411cb0ef41Sopenharmony_ci path: `/${counter++}`, 421cb0ef41Sopenharmony_ci host: 'localhost', 431cb0ef41Sopenharmony_ci port: this.address().port, 441cb0ef41Sopenharmony_ci rejectUnauthorized: false, 451cb0ef41Sopenharmony_ci }, cb).on('error', common.mustNotCall()).end(); 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ci https.request({ 481cb0ef41Sopenharmony_ci method: 'POST', 491cb0ef41Sopenharmony_ci path: `/${counter++}`, 501cb0ef41Sopenharmony_ci host: 'localhost', 511cb0ef41Sopenharmony_ci port: this.address().port, 521cb0ef41Sopenharmony_ci rejectUnauthorized: false, 531cb0ef41Sopenharmony_ci }, cb).on('error', common.mustNotCall()).end(); 541cb0ef41Sopenharmony_ci 551cb0ef41Sopenharmony_ci https.request({ 561cb0ef41Sopenharmony_ci method: 'PUT', 571cb0ef41Sopenharmony_ci path: `/${counter++}`, 581cb0ef41Sopenharmony_ci host: 'localhost', 591cb0ef41Sopenharmony_ci port: this.address().port, 601cb0ef41Sopenharmony_ci rejectUnauthorized: false, 611cb0ef41Sopenharmony_ci }, cb).on('error', common.mustNotCall()).end(); 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ci https.request({ 641cb0ef41Sopenharmony_ci method: 'DELETE', 651cb0ef41Sopenharmony_ci path: `/${counter++}`, 661cb0ef41Sopenharmony_ci host: 'localhost', 671cb0ef41Sopenharmony_ci port: this.address().port, 681cb0ef41Sopenharmony_ci rejectUnauthorized: false, 691cb0ef41Sopenharmony_ci }, cb).on('error', common.mustNotCall()).end(); 701cb0ef41Sopenharmony_ci 711cb0ef41Sopenharmony_ci https.get({ 721cb0ef41Sopenharmony_ci method: 'GET', 731cb0ef41Sopenharmony_ci path: `/setHostFalse${counter++}`, 741cb0ef41Sopenharmony_ci host: 'localhost', 751cb0ef41Sopenharmony_ci setHost: false, 761cb0ef41Sopenharmony_ci port: this.address().port, 771cb0ef41Sopenharmony_ci rejectUnauthorized: false, 781cb0ef41Sopenharmony_ci }, cb).on('error', common.mustNotCall()); 791cb0ef41Sopenharmony_ci 801cb0ef41Sopenharmony_ci https.request({ 811cb0ef41Sopenharmony_ci method: 'GET', 821cb0ef41Sopenharmony_ci path: `/${counter++}`, 831cb0ef41Sopenharmony_ci host: 'localhost', 841cb0ef41Sopenharmony_ci setHost: true, 851cb0ef41Sopenharmony_ci // agent: false, 861cb0ef41Sopenharmony_ci port: this.address().port, 871cb0ef41Sopenharmony_ci rejectUnauthorized: false, 881cb0ef41Sopenharmony_ci }, cb).on('error', common.mustNotCall()).end(); 891cb0ef41Sopenharmony_ci 901cb0ef41Sopenharmony_ci https.get({ 911cb0ef41Sopenharmony_ci method: 'GET', 921cb0ef41Sopenharmony_ci path: `/setHostFalse${counter++}`, 931cb0ef41Sopenharmony_ci host: 'localhost', 941cb0ef41Sopenharmony_ci setHost: 0, 951cb0ef41Sopenharmony_ci port: this.address().port, 961cb0ef41Sopenharmony_ci rejectUnauthorized: false, 971cb0ef41Sopenharmony_ci }, cb).on('error', common.mustNotCall()); 981cb0ef41Sopenharmony_ci 991cb0ef41Sopenharmony_ci https.get({ 1001cb0ef41Sopenharmony_ci method: 'GET', 1011cb0ef41Sopenharmony_ci path: `/setHostFalse${counter++}`, 1021cb0ef41Sopenharmony_ci host: 'localhost', 1031cb0ef41Sopenharmony_ci setHost: null, 1041cb0ef41Sopenharmony_ci port: this.address().port, 1051cb0ef41Sopenharmony_ci rejectUnauthorized: false, 1061cb0ef41Sopenharmony_ci }, cb).on('error', common.mustNotCall()); 1071cb0ef41Sopenharmony_ci})); 1081cb0ef41Sopenharmony_ci 1091cb0ef41Sopenharmony_ciconst cb = common.mustCall(function(res) { 1101cb0ef41Sopenharmony_ci counter--; 1111cb0ef41Sopenharmony_ci debug(`back from https request. counter = ${counter}`); 1121cb0ef41Sopenharmony_ci if (counter === 0) { 1131cb0ef41Sopenharmony_ci httpsServer.close(); 1141cb0ef41Sopenharmony_ci debug('ok'); 1151cb0ef41Sopenharmony_ci } 1161cb0ef41Sopenharmony_ci res.resume(); 1171cb0ef41Sopenharmony_ci}, 9); 118