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 assert = require('assert'); 111cb0ef41Sopenharmony_ciconst http = require('http'); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciclass MyIncomingMessage extends http.IncomingMessage { 141cb0ef41Sopenharmony_ci getUserAgent() { 151cb0ef41Sopenharmony_ci return this.headers['user-agent'] || 'unknown'; 161cb0ef41Sopenharmony_ci } 171cb0ef41Sopenharmony_ci} 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ciconst server = http.createServer({ 201cb0ef41Sopenharmony_ci IncomingMessage: MyIncomingMessage 211cb0ef41Sopenharmony_ci}, common.mustCall(function(req, res) { 221cb0ef41Sopenharmony_ci assert.strictEqual(req.getUserAgent(), 'node-test'); 231cb0ef41Sopenharmony_ci res.statusCode = 200; 241cb0ef41Sopenharmony_ci res.end(); 251cb0ef41Sopenharmony_ci})); 261cb0ef41Sopenharmony_ciserver.listen(); 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ciserver.on('listening', function makeRequest() { 291cb0ef41Sopenharmony_ci http.get({ 301cb0ef41Sopenharmony_ci port: this.address().port, 311cb0ef41Sopenharmony_ci headers: { 321cb0ef41Sopenharmony_ci 'User-Agent': 'node-test' 331cb0ef41Sopenharmony_ci } 341cb0ef41Sopenharmony_ci }, (res) => { 351cb0ef41Sopenharmony_ci assert.strictEqual(res.statusCode, 200); 361cb0ef41Sopenharmony_ci res.on('end', () => { 371cb0ef41Sopenharmony_ci server.close(); 381cb0ef41Sopenharmony_ci }); 391cb0ef41Sopenharmony_ci res.resume(); 401cb0ef41Sopenharmony_ci }); 411cb0ef41Sopenharmony_ci}); 42