1
1
'use strict' ;
2
- require ( '../common' ) ;
2
+ const common = require ( '../common' ) ;
3
3
const http = require ( 'http' ) ;
4
4
const assert = require ( 'assert' ) ;
5
5
const httpServer = http . createServer ( reqHandler ) ;
6
6
7
7
function reqHandler ( req , res ) {
8
- console . log ( 'Got request: ' + req . headers . host + ' ' + req . url ) ;
9
8
if ( req . url === '/setHostFalse5' ) {
10
9
assert . strictEqual ( req . headers . host , undefined ) ;
11
10
} else {
@@ -14,14 +13,9 @@ function reqHandler(req, res) {
14
13
req . headers . host ) ;
15
14
}
16
15
res . writeHead ( 200 , { } ) ;
17
- //process.nextTick(function() { res.end('ok'); });
18
16
res . end ( 'ok' ) ;
19
17
}
20
18
21
- function thrower ( er ) {
22
- throw er ;
23
- }
24
-
25
19
testHttp ( ) ;
26
20
27
21
function testHttp ( ) {
@@ -30,59 +24,52 @@ function testHttp() {
30
24
31
25
function cb ( res ) {
32
26
counter -- ;
33
- console . log ( 'back from http request. counter = ' + counter ) ;
34
27
if ( counter === 0 ) {
35
28
httpServer . close ( ) ;
36
29
}
37
30
res . resume ( ) ;
38
31
}
39
32
40
- httpServer . listen ( 0 , function ( er ) {
41
- console . error ( `test http server listening on ${ this . address ( ) . port } ` ) ;
33
+ httpServer . listen ( 0 , ( er ) => {
42
34
assert . ifError ( er ) ;
43
35
http . get ( {
44
36
method : 'GET' ,
45
37
path : '/' + ( counter ++ ) ,
46
38
host : 'localhost' ,
47
- //agent: false,
48
- port : this . address ( ) . port ,
39
+ port : httpServer . address ( ) . port ,
49
40
rejectUnauthorized : false
50
- } , cb ) . on ( 'error' , thrower ) ;
41
+ } , cb ) . on ( 'error' , common . fail ) ;
51
42
52
43
http . request ( {
53
44
method : 'GET' ,
54
45
path : '/' + ( counter ++ ) ,
55
46
host : 'localhost' ,
56
- //agent: false,
57
- port : this . address ( ) . port ,
47
+ port : httpServer . address ( ) . port ,
58
48
rejectUnauthorized : false
59
- } , cb ) . on ( 'error' , thrower ) . end ( ) ;
49
+ } , cb ) . on ( 'error' , common . fail ) . end ( ) ;
60
50
61
51
http . request ( {
62
52
method : 'POST' ,
63
53
path : '/' + ( counter ++ ) ,
64
54
host : 'localhost' ,
65
- //agent: false,
66
- port : this . address ( ) . port ,
55
+ port : httpServer . address ( ) . port ,
67
56
rejectUnauthorized : false
68
- } , cb ) . on ( 'error' , thrower ) . end ( ) ;
57
+ } , cb ) . on ( 'error' , common . fail ) . end ( ) ;
69
58
70
59
http . request ( {
71
60
method : 'PUT' ,
72
61
path : '/' + ( counter ++ ) ,
73
62
host : 'localhost' ,
74
- //agent: false,
75
- port : this . address ( ) . port ,
63
+ port : httpServer . address ( ) . port ,
76
64
rejectUnauthorized : false
77
- } , cb ) . on ( 'error' , thrower ) . end ( ) ;
65
+ } , cb ) . on ( 'error' , common . fail ) . end ( ) ;
78
66
79
67
http . request ( {
80
68
method : 'DELETE' ,
81
69
path : '/' + ( counter ++ ) ,
82
70
host : 'localhost' ,
83
- //agent: false,
84
- port : this . address ( ) . port ,
71
+ port : httpServer . address ( ) . port ,
85
72
rejectUnauthorized : false
86
- } , cb ) . on ( 'error' , thrower ) . end ( ) ;
73
+ } , cb ) . on ( 'error' , common . fail ) . end ( ) ;
87
74
} ) ;
88
75
}
0 commit comments