11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci/**
41cb0ef41Sopenharmony_ci * This test covers http.Server({ IncomingMessage }) option:
51cb0ef41Sopenharmony_ci * With IncomingMessage option the server should use
61cb0ef41Sopenharmony_ci * the new class for creating req Object instead of the default
71cb0ef41Sopenharmony_ci * http.IncomingMessage.
81cb0ef41Sopenharmony_ci */
91cb0ef41Sopenharmony_ciconst common = require('../common');
101cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciif (!common.hasCrypto)
131cb0ef41Sopenharmony_ci  common.skip('missing crypto');
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciconst assert = require('assert');
161cb0ef41Sopenharmony_ciconst http = require('http');
171cb0ef41Sopenharmony_ciconst https = require('https');
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciclass MyIncomingMessage extends http.IncomingMessage {
201cb0ef41Sopenharmony_ci  getUserAgent() {
211cb0ef41Sopenharmony_ci    return this.headers['user-agent'] || 'unknown';
221cb0ef41Sopenharmony_ci  }
231cb0ef41Sopenharmony_ci}
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ciconst server = https.createServer({
261cb0ef41Sopenharmony_ci  key: fixtures.readKey('agent1-key.pem'),
271cb0ef41Sopenharmony_ci  cert: fixtures.readKey('agent1-cert.pem'),
281cb0ef41Sopenharmony_ci  ca: fixtures.readKey('ca1-cert.pem'),
291cb0ef41Sopenharmony_ci  IncomingMessage: MyIncomingMessage
301cb0ef41Sopenharmony_ci}, common.mustCall(function(req, res) {
311cb0ef41Sopenharmony_ci  assert.strictEqual(req.getUserAgent(), 'node-test');
321cb0ef41Sopenharmony_ci  res.statusCode = 200;
331cb0ef41Sopenharmony_ci  res.end();
341cb0ef41Sopenharmony_ci}));
351cb0ef41Sopenharmony_ciserver.listen();
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ciserver.on('listening', function makeRequest() {
381cb0ef41Sopenharmony_ci  https.get({
391cb0ef41Sopenharmony_ci    port: this.address().port,
401cb0ef41Sopenharmony_ci    rejectUnauthorized: false,
411cb0ef41Sopenharmony_ci    headers: {
421cb0ef41Sopenharmony_ci      'User-Agent': 'node-test'
431cb0ef41Sopenharmony_ci    }
441cb0ef41Sopenharmony_ci  }, (res) => {
451cb0ef41Sopenharmony_ci    assert.strictEqual(res.statusCode, 200);
461cb0ef41Sopenharmony_ci    res.on('end', () => {
471cb0ef41Sopenharmony_ci      server.close();
481cb0ef41Sopenharmony_ci    });
491cb0ef41Sopenharmony_ci    res.resume();
501cb0ef41Sopenharmony_ci  });
511cb0ef41Sopenharmony_ci});
52