@@ -34,54 +34,27 @@ const options = {
34
34
key : fixtures . readKey ( 'agent1-key.pem' ) ,
35
35
cert : fixtures . readKey ( 'agent1-cert.pem' )
36
36
} ;
37
- let gotHttpsResp = false ;
38
- let gotHttpResp = false ;
39
37
40
- process . on ( 'exit' , function ( ) {
41
- if ( common . hasCrypto ) {
42
- assert ( gotHttpsResp ) ;
43
- }
44
- assert ( gotHttpResp ) ;
45
- console . log ( 'ok' ) ;
46
- } ) ;
47
-
48
- http . createServer ( function ( req , res ) {
49
- assert . strictEqual ( req . headers . host , hostExpect ) ;
50
- assert . strictEqual ( req . headers [ 'x-port' ] , this . address ( ) . port . toString ( ) ) ;
51
- res . writeHead ( 200 ) ;
52
- res . end ( 'ok' ) ;
53
- this . close ( ) ;
54
- } ) . listen ( 0 , function ( ) {
55
- http . globalAgent . defaultPort = this . address ( ) . port ;
56
- http . get ( {
57
- host : 'localhost' ,
58
- headers : {
59
- 'x-port' : this . address ( ) . port
60
- }
61
- } , function ( res ) {
62
- gotHttpResp = true ;
63
- res . resume ( ) ;
64
- } ) ;
65
- } ) ;
66
-
67
- if ( common . hasCrypto ) {
68
- https . createServer ( options , function ( req , res ) {
38
+ for ( const { mod, createServer } of [
39
+ { mod : http , createServer : http . createServer } ,
40
+ { mod : https , createServer : https . createServer . bind ( null , options ) }
41
+ ] ) {
42
+ const server = createServer ( common . mustCall ( ( req , res ) => {
69
43
assert . strictEqual ( req . headers . host , hostExpect ) ;
70
- assert . strictEqual ( req . headers [ 'x-port' ] , this . address ( ) . port . toString ( ) ) ;
44
+ assert . strictEqual ( req . headers [ 'x-port' ] , ` ${ server . address ( ) . port } ` ) ;
71
45
res . writeHead ( 200 ) ;
72
46
res . end ( 'ok' ) ;
73
- this . close ( ) ;
74
- } ) . listen ( 0 , function ( ) {
75
- https . globalAgent . defaultPort = this . address ( ) . port ;
76
- https . get ( {
47
+ server . close ( ) ;
48
+ } ) ) . listen ( 0 , common . mustCall ( ( ) => {
49
+ mod . globalAgent . defaultPort = server . address ( ) . port ;
50
+ mod . get ( {
77
51
host : 'localhost' ,
78
52
rejectUnauthorized : false ,
79
53
headers : {
80
- 'x-port' : this . address ( ) . port
54
+ 'x-port' : server . address ( ) . port
81
55
}
82
- } , function ( res ) {
83
- gotHttpsResp = true ;
56
+ } , common . mustCall ( ( res ) => {
84
57
res . resume ( ) ;
85
- } ) ;
86
- } ) ;
58
+ } ) ) ;
59
+ } ) ) ;
87
60
}
0 commit comments