11'use strict' ;
2- require ( '../common' ) ;
2+ const common = require ( '../common' ) ;
33const http = require ( 'http' ) ;
44const assert = require ( 'assert' ) ;
55const httpServer = http . createServer ( reqHandler ) ;
66
77function reqHandler ( req , res ) {
8- console . log ( 'Got request: ' + req . headers . host + ' ' + req . url ) ;
98 if ( req . url === '/setHostFalse5' ) {
109 assert . strictEqual ( req . headers . host , undefined ) ;
1110 } else {
@@ -14,14 +13,9 @@ function reqHandler(req, res) {
1413 req . headers . host ) ;
1514 }
1615 res . writeHead ( 200 , { } ) ;
17- //process.nextTick(function() { res.end('ok'); });
1816 res . end ( 'ok' ) ;
1917}
2018
21- function thrower ( er ) {
22- throw er ;
23- }
24-
2519testHttp ( ) ;
2620
2721function testHttp ( ) {
@@ -30,59 +24,52 @@ function testHttp() {
3024
3125 function cb ( res ) {
3226 counter -- ;
33- console . log ( 'back from http request. counter = ' + counter ) ;
3427 if ( counter === 0 ) {
3528 httpServer . close ( ) ;
3629 }
3730 res . resume ( ) ;
3831 }
3932
40- httpServer . listen ( 0 , function ( er ) {
41- console . error ( `test http server listening on ${ this . address ( ) . port } ` ) ;
33+ httpServer . listen ( 0 , ( er ) => {
4234 assert . ifError ( er ) ;
4335 http . get ( {
4436 method : 'GET' ,
4537 path : '/' + ( counter ++ ) ,
4638 host : 'localhost' ,
47- //agent: false,
48- port : this . address ( ) . port ,
39+ port : httpServer . address ( ) . port ,
4940 rejectUnauthorized : false
50- } , cb ) . on ( 'error' , thrower ) ;
41+ } , cb ) . on ( 'error' , common . fail ) ;
5142
5243 http . request ( {
5344 method : 'GET' ,
5445 path : '/' + ( counter ++ ) ,
5546 host : 'localhost' ,
56- //agent: false,
57- port : this . address ( ) . port ,
47+ port : httpServer . address ( ) . port ,
5848 rejectUnauthorized : false
59- } , cb ) . on ( 'error' , thrower ) . end ( ) ;
49+ } , cb ) . on ( 'error' , common . fail ) . end ( ) ;
6050
6151 http . request ( {
6252 method : 'POST' ,
6353 path : '/' + ( counter ++ ) ,
6454 host : 'localhost' ,
65- //agent: false,
66- port : this . address ( ) . port ,
55+ port : httpServer . address ( ) . port ,
6756 rejectUnauthorized : false
68- } , cb ) . on ( 'error' , thrower ) . end ( ) ;
57+ } , cb ) . on ( 'error' , common . fail ) . end ( ) ;
6958
7059 http . request ( {
7160 method : 'PUT' ,
7261 path : '/' + ( counter ++ ) ,
7362 host : 'localhost' ,
74- //agent: false,
75- port : this . address ( ) . port ,
63+ port : httpServer . address ( ) . port ,
7664 rejectUnauthorized : false
77- } , cb ) . on ( 'error' , thrower ) . end ( ) ;
65+ } , cb ) . on ( 'error' , common . fail ) . end ( ) ;
7866
7967 http . request ( {
8068 method : 'DELETE' ,
8169 path : '/' + ( counter ++ ) ,
8270 host : 'localhost' ,
83- //agent: false,
84- port : this . address ( ) . port ,
71+ port : httpServer . address ( ) . port ,
8572 rejectUnauthorized : false
86- } , cb ) . on ( 'error' , thrower ) . end ( ) ;
73+ } , cb ) . on ( 'error' , common . fail ) . end ( ) ;
8774 } ) ;
8875}
0 commit comments