11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciif (!common.hasCrypto)
61cb0ef41Sopenharmony_ci  common.skip('missing crypto');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
91cb0ef41Sopenharmony_ciconst https = require('https');
101cb0ef41Sopenharmony_ciconst tls = require('tls');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciconst tests = [];
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ciconst serverOptions = {
151cb0ef41Sopenharmony_ci  key: fixtures.readKey('agent1-key.pem'),
161cb0ef41Sopenharmony_ci  cert: fixtures.readKey('agent1-cert.pem')
171cb0ef41Sopenharmony_ci};
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_cifunction test(fn) {
201cb0ef41Sopenharmony_ci  if (!tests.length) {
211cb0ef41Sopenharmony_ci    process.nextTick(run);
221cb0ef41Sopenharmony_ci  }
231cb0ef41Sopenharmony_ci  tests.push(fn);
241cb0ef41Sopenharmony_ci}
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_cifunction run() {
271cb0ef41Sopenharmony_ci  const fn = tests.shift();
281cb0ef41Sopenharmony_ci  if (fn) fn(run);
291cb0ef41Sopenharmony_ci}
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_citest(function serverKeepAliveTimeoutWithPipeline(cb) {
321cb0ef41Sopenharmony_ci  const server = https.createServer(
331cb0ef41Sopenharmony_ci    serverOptions,
341cb0ef41Sopenharmony_ci    common.mustCall((req, res) => {
351cb0ef41Sopenharmony_ci      res.end();
361cb0ef41Sopenharmony_ci    }, 3));
371cb0ef41Sopenharmony_ci  server.setTimeout(common.platformTimeout(500), common.mustCall((socket) => {
381cb0ef41Sopenharmony_ci    // End this test and call `run()` for the next test (if any).
391cb0ef41Sopenharmony_ci    socket.destroy();
401cb0ef41Sopenharmony_ci    server.close();
411cb0ef41Sopenharmony_ci    cb();
421cb0ef41Sopenharmony_ci  }));
431cb0ef41Sopenharmony_ci  server.keepAliveTimeout = common.platformTimeout(50);
441cb0ef41Sopenharmony_ci  server.listen(0, common.mustCall(() => {
451cb0ef41Sopenharmony_ci    const options = {
461cb0ef41Sopenharmony_ci      port: server.address().port,
471cb0ef41Sopenharmony_ci      allowHalfOpen: true,
481cb0ef41Sopenharmony_ci      rejectUnauthorized: false
491cb0ef41Sopenharmony_ci    };
501cb0ef41Sopenharmony_ci    const c = tls.connect(options, () => {
511cb0ef41Sopenharmony_ci      c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n');
521cb0ef41Sopenharmony_ci      c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n');
531cb0ef41Sopenharmony_ci      c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n');
541cb0ef41Sopenharmony_ci    });
551cb0ef41Sopenharmony_ci  }));
561cb0ef41Sopenharmony_ci});
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_citest(function serverNoEndKeepAliveTimeoutWithPipeline(cb) {
591cb0ef41Sopenharmony_ci  const server = https.createServer(serverOptions, common.mustCall(3));
601cb0ef41Sopenharmony_ci  server.setTimeout(common.platformTimeout(500), common.mustCall((socket) => {
611cb0ef41Sopenharmony_ci    // End this test and call `run()` for the next test (if any).
621cb0ef41Sopenharmony_ci    socket.destroy();
631cb0ef41Sopenharmony_ci    server.close();
641cb0ef41Sopenharmony_ci    cb();
651cb0ef41Sopenharmony_ci  }));
661cb0ef41Sopenharmony_ci  server.keepAliveTimeout = common.platformTimeout(50);
671cb0ef41Sopenharmony_ci  server.listen(0, common.mustCall(() => {
681cb0ef41Sopenharmony_ci    const options = {
691cb0ef41Sopenharmony_ci      port: server.address().port,
701cb0ef41Sopenharmony_ci      allowHalfOpen: true,
711cb0ef41Sopenharmony_ci      rejectUnauthorized: false
721cb0ef41Sopenharmony_ci    };
731cb0ef41Sopenharmony_ci    const c = tls.connect(options, () => {
741cb0ef41Sopenharmony_ci      c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n');
751cb0ef41Sopenharmony_ci      c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n');
761cb0ef41Sopenharmony_ci      c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n');
771cb0ef41Sopenharmony_ci    });
781cb0ef41Sopenharmony_ci  }));
791cb0ef41Sopenharmony_ci});
80