11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst EventEmitter = require('events'); 61cb0ef41Sopenharmony_ciconst http = require('http'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst ee = new EventEmitter(); 91cb0ef41Sopenharmony_cilet count = 3; 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst server = http.createServer(function(req, res) { 121cb0ef41Sopenharmony_ci res.setHeader('testing_123', 123); 131cb0ef41Sopenharmony_ci assert.throws(function() { 141cb0ef41Sopenharmony_ci res.setHeader('testing 123', 123); 151cb0ef41Sopenharmony_ci }, TypeError); 161cb0ef41Sopenharmony_ci res.end(''); 171cb0ef41Sopenharmony_ci}); 181cb0ef41Sopenharmony_ciserver.listen(0, function() { 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci http.get({ port: this.address().port }, function() { 211cb0ef41Sopenharmony_ci ee.emit('done'); 221cb0ef41Sopenharmony_ci }); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci assert.throws( 251cb0ef41Sopenharmony_ci function() { 261cb0ef41Sopenharmony_ci const options = { 271cb0ef41Sopenharmony_ci port: server.address().port, 281cb0ef41Sopenharmony_ci headers: { 'testing 123': 123 } 291cb0ef41Sopenharmony_ci }; 301cb0ef41Sopenharmony_ci http.get(options, common.mustNotCall()); 311cb0ef41Sopenharmony_ci }, 321cb0ef41Sopenharmony_ci function(err) { 331cb0ef41Sopenharmony_ci ee.emit('done'); 341cb0ef41Sopenharmony_ci if (err instanceof TypeError) return true; 351cb0ef41Sopenharmony_ci } 361cb0ef41Sopenharmony_ci ); 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci // Should not throw. 391cb0ef41Sopenharmony_ci const options = { 401cb0ef41Sopenharmony_ci port: server.address().port, 411cb0ef41Sopenharmony_ci headers: { 'testing_123': 123 } 421cb0ef41Sopenharmony_ci }; 431cb0ef41Sopenharmony_ci http.get(options, function() { 441cb0ef41Sopenharmony_ci ee.emit('done'); 451cb0ef41Sopenharmony_ci }); 461cb0ef41Sopenharmony_ci}); 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ciee.on('done', function() { 491cb0ef41Sopenharmony_ci if (--count === 0) { 501cb0ef41Sopenharmony_ci server.close(); 511cb0ef41Sopenharmony_ci } 521cb0ef41Sopenharmony_ci}); 53