@@ -6,7 +6,9 @@ if (!common.hasCrypto) {
6
6
common . skip ( 'missing crypto' ) ;
7
7
return ;
8
8
}
9
+
9
10
const https = require ( 'https' ) ;
11
+ const http = require ( 'http' ) ;
10
12
11
13
const tls = require ( 'tls' ) ;
12
14
const fs = require ( 'fs' ) ;
@@ -35,83 +37,93 @@ function run() {
35
37
}
36
38
37
39
test ( function serverTimeout ( cb ) {
38
- const server = https . createServer ( serverOptions , function ( req , res ) {
39
- // just do nothing, we should get a timeout event.
40
- } ) ;
41
- server . listen ( 0 , common . mustCall ( function ( ) {
40
+ const server = https . createServer (
41
+ serverOptions ,
42
+ common . mustCall ( function ( req , res ) {
43
+ // just do nothing, we should get a
44
+ // timeout event.
45
+ } ) ) ;
46
+ server . listen ( common . mustCall ( function ( ) {
42
47
const s = server . setTimeout ( 50 , common . mustCall ( function ( socket ) {
43
48
socket . destroy ( ) ;
44
49
server . close ( ) ;
45
50
cb ( ) ;
46
51
} ) ) ;
47
52
assert . ok ( s instanceof https . Server ) ;
48
53
https . get ( {
49
- port : this . address ( ) . port ,
54
+ port : server . address ( ) . port ,
50
55
rejectUnauthorized : false
51
56
} ) . on ( 'error' , common . noop ) ;
52
57
} ) ) ;
53
58
} ) ;
54
59
55
60
test ( function serverRequestTimeout ( cb ) {
56
- function handler ( req , res ) {
57
- // just do nothing, we should get a timeout event.
58
- req . setTimeout ( 50 , common . mustCall ( function ( ) {
59
- req . socket . destroy ( ) ;
60
- server . close ( ) ;
61
- cb ( ) ;
61
+ const server = https . createServer (
62
+ serverOptions ,
63
+ common . mustCall ( function ( req , res ) {
64
+ // just do nothing, we should get a
65
+ // timeout event.
66
+ const s = req . setTimeout (
67
+ 50 ,
68
+ common . mustCall ( function ( socket ) {
69
+ socket . destroy ( ) ;
70
+ server . close ( ) ;
71
+ cb ( ) ;
72
+ } ) ) ;
73
+ assert . ok ( s instanceof http . IncomingMessage ) ;
62
74
} ) ) ;
63
- }
64
-
65
- let server = https . createServer ( serverOptions , common . mustCall ( handler ) ) ;
66
- server . listen ( 0 , function ( ) {
75
+ server . listen ( common . mustCall ( function ( ) {
67
76
const req = https . request ( {
68
- port : this . address ( ) . port ,
77
+ port : server . address ( ) . port ,
69
78
method : 'POST' ,
70
79
rejectUnauthorized : false
71
80
} ) ;
72
81
req . on ( 'error' , common . noop ) ;
73
82
req . write ( 'Hello' ) ;
74
83
// req is in progress
75
- } ) ;
84
+ } ) ) ;
76
85
} ) ;
77
86
78
87
test ( function serverResponseTimeout ( cb ) {
79
- function handler ( req , res ) {
80
- // just do nothing, we should get a timeout event.
81
- res . setTimeout ( 50 , common . mustCall ( function ( ) {
82
- res . socket . destroy ( ) ;
83
- server . close ( ) ;
84
- cb ( ) ;
88
+ const server = https . createServer (
89
+ serverOptions ,
90
+ common . mustCall ( function ( req , res ) {
91
+ // just do nothing, we should get a timeout event.
92
+ const s = res . setTimeout ( 50 , common . mustCall ( function ( socket ) {
93
+ socket . destroy ( ) ;
94
+ server . close ( ) ;
95
+ cb ( ) ;
96
+ } ) ) ;
97
+ assert . ok ( s instanceof http . OutgoingMessage ) ;
85
98
} ) ) ;
86
- }
87
-
88
- let server = https . createServer ( serverOptions , common . mustCall ( handler ) ) ;
89
- server . listen ( 0 , function ( ) {
99
+ server . listen ( common . mustCall ( function ( ) {
90
100
https . get ( {
91
- port : this . address ( ) . port ,
101
+ port : server . address ( ) . port ,
92
102
rejectUnauthorized : false
93
- } ) . on ( 'error' , common . noop ) ;
94
- } ) ;
103
+ } ) . on ( 'error' , common . mustCall ( ) ) ;
104
+ } ) ) ;
95
105
} ) ;
96
106
97
107
test ( function serverRequestNotTimeoutAfterEnd ( cb ) {
98
- function handler ( req , res ) {
99
- // just do nothing, we should get a timeout event.
100
- req . setTimeout ( 50 , common . mustNotCall ( ) ) ;
101
- res . on ( 'timeout' , common . mustCall ( function ( socket ) { } ) ) ;
102
- }
103
- const server = https . createServer ( serverOptions , common . mustCall ( handler ) ) ;
104
- server . on ( 'timeout' , function ( socket ) {
108
+ const server = https . createServer (
109
+ serverOptions ,
110
+ common . mustCall ( function ( req , res ) {
111
+ // just do nothing, we should get a timeout event.
112
+ const s = req . setTimeout ( 50 , common . mustNotCall ( ) ) ;
113
+ assert . ok ( s instanceof http . IncomingMessage ) ;
114
+ res . on ( 'timeout' , common . mustCall ( ) ) ;
115
+ } ) ) ;
116
+ server . on ( 'timeout' , common . mustCall ( function ( socket ) {
105
117
socket . destroy ( ) ;
106
118
server . close ( ) ;
107
119
cb ( ) ;
108
- } ) ;
109
- server . listen ( 0 , function ( ) {
120
+ } ) ) ;
121
+ server . listen ( common . mustCall ( function ( ) {
110
122
https . get ( {
111
- port : this . address ( ) . port ,
123
+ port : server . address ( ) . port ,
112
124
rejectUnauthorized : false
113
- } ) . on ( 'error' , common . noop ) ;
114
- } ) ;
125
+ } ) . on ( 'error' , common . mustCall ( ) ) ;
126
+ } ) ) ;
115
127
} ) ;
116
128
117
129
test ( function serverResponseTimeoutWithPipeline ( cb ) {
@@ -123,9 +135,10 @@ test(function serverResponseTimeoutWithPipeline(cb) {
123
135
const server = https . createServer ( serverOptions , function ( req , res ) {
124
136
if ( req . url === '/2' )
125
137
secReceived = true ;
126
- res . setTimeout ( 50 , function ( ) {
138
+ const s = res . setTimeout ( 50 , function ( ) {
127
139
caughtTimeout += req . url ;
128
140
} ) ;
141
+ assert . ok ( s instanceof http . OutgoingMessage ) ;
129
142
if ( req . url === '/1' ) res . end ( ) ;
130
143
} ) ;
131
144
server . on ( 'timeout' , function ( socket ) {
@@ -135,9 +148,9 @@ test(function serverResponseTimeoutWithPipeline(cb) {
135
148
cb ( ) ;
136
149
}
137
150
} ) ;
138
- server . listen ( 0 , function ( ) {
151
+ server . listen ( common . mustCall ( function ( ) {
139
152
const options = {
140
- port : this . address ( ) . port ,
153
+ port : server . address ( ) . port ,
141
154
allowHalfOpen : true ,
142
155
rejectUnauthorized : false
143
156
} ;
@@ -146,30 +159,32 @@ test(function serverResponseTimeoutWithPipeline(cb) {
146
159
c . write ( 'GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n' ) ;
147
160
c . write ( 'GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n' ) ;
148
161
} ) ;
149
- } ) ;
162
+ } ) ) ;
150
163
} ) ;
151
164
152
165
test ( function idleTimeout ( cb ) {
153
- const server = https . createServer ( serverOptions ,
154
- common . mustCall ( function ( req , res ) {
155
- req . on ( 'timeout' , common . mustNotCall ( ) ) ;
156
- res . on ( 'timeout' , common . mustNotCall ( ) ) ;
157
- res . end ( ) ;
158
- } ) ) ;
159
- server . setTimeout ( 50 , common . mustCall ( function ( socket ) {
166
+ const server = https . createServer (
167
+ serverOptions ,
168
+ common . mustCall ( function ( req , res ) {
169
+ req . on ( 'timeout' , common . mustNotCall ( ) ) ;
170
+ res . on ( 'timeout' , common . mustNotCall ( ) ) ;
171
+ res . end ( ) ;
172
+ } ) ) ;
173
+ const s = server . setTimeout ( 50 , common . mustCall ( function ( socket ) {
160
174
socket . destroy ( ) ;
161
175
server . close ( ) ;
162
176
cb ( ) ;
163
177
} ) ) ;
164
- server . listen ( 0 , function ( ) {
178
+ assert . ok ( s instanceof https . Server ) ;
179
+ server . listen ( common . mustCall ( function ( ) {
165
180
const options = {
166
- port : this . address ( ) . port ,
181
+ port : server . address ( ) . port ,
167
182
allowHalfOpen : true ,
168
183
rejectUnauthorized : false
169
184
} ;
170
185
tls . connect ( options , function ( ) {
171
186
this . write ( 'GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n' ) ;
172
187
// Keep-Alive
173
188
} ) ;
174
- } ) ;
189
+ } ) ) ;
175
190
} ) ;
0 commit comments