11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci// Test https highWaterMark
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst common = require('../common');
61cb0ef41Sopenharmony_ciif (!common.hasCrypto)
71cb0ef41Sopenharmony_ci  common.skip('missing crypto');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst assert = require('assert');
101cb0ef41Sopenharmony_ciconst https = require('https');
111cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_cilet counter = 0;
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_cifunction loadCallback(highWaterMark) {
161cb0ef41Sopenharmony_ci  return common.mustCall(function(res) {
171cb0ef41Sopenharmony_ci    assert.strictEqual(highWaterMark, res.readableHighWaterMark);
181cb0ef41Sopenharmony_ci    counter--;
191cb0ef41Sopenharmony_ci    console.log('back from https request. ',
201cb0ef41Sopenharmony_ci                `highWaterMark = ${res.readableHighWaterMark}`);
211cb0ef41Sopenharmony_ci    if (counter === 0) {
221cb0ef41Sopenharmony_ci      httpsServer.close();
231cb0ef41Sopenharmony_ci      console.log('ok');
241cb0ef41Sopenharmony_ci    }
251cb0ef41Sopenharmony_ci    res.resume();
261cb0ef41Sopenharmony_ci  });
271cb0ef41Sopenharmony_ci}
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci// create server
301cb0ef41Sopenharmony_ciconst httpsServer = https.createServer({
311cb0ef41Sopenharmony_ci  key: fixtures.readKey('agent1-key.pem'),
321cb0ef41Sopenharmony_ci  cert: fixtures.readKey('agent1-cert.pem')
331cb0ef41Sopenharmony_ci}, common.mustCall(function(req, res) {
341cb0ef41Sopenharmony_ci  res.writeHead(200, {});
351cb0ef41Sopenharmony_ci  res.end('ok');
361cb0ef41Sopenharmony_ci}, 3)).listen(0, common.mustCall(function(err) {
371cb0ef41Sopenharmony_ci  console.log(`test https server listening on port ${this.address().port}`);
381cb0ef41Sopenharmony_ci  assert.ifError(err);
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci  https.request({
411cb0ef41Sopenharmony_ci    method: 'GET',
421cb0ef41Sopenharmony_ci    path: `/${counter++}`,
431cb0ef41Sopenharmony_ci    host: 'localhost',
441cb0ef41Sopenharmony_ci    port: this.address().port,
451cb0ef41Sopenharmony_ci    rejectUnauthorized: false,
461cb0ef41Sopenharmony_ci    highWaterMark: 128000,
471cb0ef41Sopenharmony_ci  }, loadCallback(128000)).on('error', common.mustNotCall()).end();
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ci  https.request({
501cb0ef41Sopenharmony_ci    method: 'GET',
511cb0ef41Sopenharmony_ci    path: `/${counter++}`,
521cb0ef41Sopenharmony_ci    host: 'localhost',
531cb0ef41Sopenharmony_ci    port: this.address().port,
541cb0ef41Sopenharmony_ci    rejectUnauthorized: false,
551cb0ef41Sopenharmony_ci    highWaterMark: 0,
561cb0ef41Sopenharmony_ci  }, loadCallback(0)).on('error', common.mustNotCall()).end();
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ci  https.request({
591cb0ef41Sopenharmony_ci    method: 'GET',
601cb0ef41Sopenharmony_ci    path: `/${counter++}`,
611cb0ef41Sopenharmony_ci    host: 'localhost',
621cb0ef41Sopenharmony_ci    port: this.address().port,
631cb0ef41Sopenharmony_ci    rejectUnauthorized: false,
641cb0ef41Sopenharmony_ci    highWaterMark: undefined,
651cb0ef41Sopenharmony_ci  }, loadCallback(16 * 1024)).on('error', common.mustNotCall()).end();
661cb0ef41Sopenharmony_ci}));
67