@@ -30,6 +30,7 @@ if (!common.hasCrypto) {
30
30
const assert = require ( 'assert' ) ;
31
31
const fs = require ( 'fs' ) ;
32
32
const https = require ( 'https' ) ;
33
+ const http = require ( 'http' ) ;
33
34
const tls = require ( 'tls' ) ;
34
35
35
36
const tests = [ ] ;
@@ -56,83 +57,93 @@ function run() {
56
57
}
57
58
58
59
test ( function serverTimeout ( cb ) {
59
- const server = https . createServer ( serverOptions , function ( req , res ) {
60
- // just do nothing, we should get a timeout event.
61
- } ) ;
62
- server . listen ( 0 , common . mustCall ( function ( ) {
60
+ const server = https . createServer (
61
+ serverOptions ,
62
+ common . mustCall ( function ( req , res ) {
63
+ // just do nothing, we should get a
64
+ // timeout event.
65
+ } ) ) ;
66
+ server . listen ( common . mustCall ( function ( ) {
63
67
const s = server . setTimeout ( 50 , common . mustCall ( function ( socket ) {
64
68
socket . destroy ( ) ;
65
69
server . close ( ) ;
66
70
cb ( ) ;
67
71
} ) ) ;
68
72
assert . ok ( s instanceof https . Server ) ;
69
73
https . get ( {
70
- port : this . address ( ) . port ,
74
+ port : server . address ( ) . port ,
71
75
rejectUnauthorized : false
72
76
} ) . on ( 'error' , common . mustCall ( ) ) ;
73
77
} ) ) ;
74
78
} ) ;
75
79
76
80
test ( function serverRequestTimeout ( cb ) {
77
- function handler ( req , res ) {
78
- // just do nothing, we should get a timeout event.
79
- req . setTimeout ( 50 , common . mustCall ( function ( ) {
80
- req . socket . destroy ( ) ;
81
- server . close ( ) ;
82
- cb ( ) ;
81
+ const server = https . createServer (
82
+ serverOptions ,
83
+ common . mustCall ( function ( req , res ) {
84
+ // just do nothing, we should get a
85
+ // timeout event.
86
+ const s = req . setTimeout (
87
+ 50 ,
88
+ common . mustCall ( function ( socket ) {
89
+ socket . destroy ( ) ;
90
+ server . close ( ) ;
91
+ cb ( ) ;
92
+ } ) ) ;
93
+ assert . ok ( s instanceof http . IncomingMessage ) ;
83
94
} ) ) ;
84
- }
85
-
86
- const server = https . createServer ( serverOptions , common . mustCall ( handler ) ) ;
87
- server . listen ( 0 , function ( ) {
95
+ server . listen ( common . mustCall ( function ( ) {
88
96
const req = https . request ( {
89
- port : this . address ( ) . port ,
97
+ port : server . address ( ) . port ,
90
98
method : 'POST' ,
91
99
rejectUnauthorized : false
92
100
} ) ;
93
101
req . on ( 'error' , common . mustCall ( ) ) ;
94
102
req . write ( 'Hello' ) ;
95
103
// req is in progress
96
- } ) ;
104
+ } ) ) ;
97
105
} ) ;
98
106
99
107
test ( function serverResponseTimeout ( cb ) {
100
- function handler ( req , res ) {
101
- // just do nothing, we should get a timeout event.
102
- res . setTimeout ( 50 , common . mustCall ( function ( ) {
103
- res . socket . destroy ( ) ;
104
- server . close ( ) ;
105
- cb ( ) ;
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 = res . setTimeout ( 50 , common . mustCall ( function ( socket ) {
113
+ socket . destroy ( ) ;
114
+ server . close ( ) ;
115
+ cb ( ) ;
116
+ } ) ) ;
117
+ assert . ok ( s instanceof http . OutgoingMessage ) ;
106
118
} ) ) ;
107
- }
108
-
109
- const server = https . createServer ( serverOptions , common . mustCall ( handler ) ) ;
110
- server . listen ( 0 , function ( ) {
119
+ server . listen ( common . mustCall ( function ( ) {
111
120
https . get ( {
112
- port : this . address ( ) . port ,
121
+ port : server . address ( ) . port ,
113
122
rejectUnauthorized : false
114
123
} ) . on ( 'error' , common . mustCall ( ) ) ;
115
- } ) ;
124
+ } ) ) ;
116
125
} ) ;
117
126
118
127
test ( function serverRequestNotTimeoutAfterEnd ( cb ) {
119
- function handler ( req , res ) {
120
- // just do nothing, we should get a timeout event.
121
- req . setTimeout ( 50 , common . mustNotCall ( ) ) ;
122
- res . on ( 'timeout' , common . mustCall ( ) ) ;
123
- }
124
- const server = https . createServer ( serverOptions , common . mustCall ( handler ) ) ;
125
- server . on ( 'timeout' , function ( socket ) {
128
+ const server = https . createServer (
129
+ serverOptions ,
130
+ common . mustCall ( function ( req , res ) {
131
+ // just do nothing, we should get a timeout event.
132
+ const s = req . setTimeout ( 50 , common . mustNotCall ( ) ) ;
133
+ assert . ok ( s instanceof http . IncomingMessage ) ;
134
+ res . on ( 'timeout' , common . mustCall ( ) ) ;
135
+ } ) ) ;
136
+ server . on ( 'timeout' , common . mustCall ( function ( socket ) {
126
137
socket . destroy ( ) ;
127
138
server . close ( ) ;
128
139
cb ( ) ;
129
- } ) ;
130
- server . listen ( 0 , function ( ) {
140
+ } ) ) ;
141
+ server . listen ( common . mustCall ( function ( ) {
131
142
https . get ( {
132
- port : this . address ( ) . port ,
143
+ port : server . address ( ) . port ,
133
144
rejectUnauthorized : false
134
145
} ) . on ( 'error' , common . mustCall ( ) ) ;
135
- } ) ;
146
+ } ) ) ;
136
147
} ) ;
137
148
138
149
test ( function serverResponseTimeoutWithPipeline ( cb ) {
@@ -144,9 +155,10 @@ test(function serverResponseTimeoutWithPipeline(cb) {
144
155
const server = https . createServer ( serverOptions , function ( req , res ) {
145
156
if ( req . url === '/2' )
146
157
secReceived = true ;
147
- res . setTimeout ( 50 , function ( ) {
158
+ const s = res . setTimeout ( 50 , function ( ) {
148
159
caughtTimeout += req . url ;
149
160
} ) ;
161
+ assert . ok ( s instanceof http . OutgoingMessage ) ;
150
162
if ( req . url === '/1' ) res . end ( ) ;
151
163
} ) ;
152
164
server . on ( 'timeout' , function ( socket ) {
@@ -156,9 +168,9 @@ test(function serverResponseTimeoutWithPipeline(cb) {
156
168
cb ( ) ;
157
169
}
158
170
} ) ;
159
- server . listen ( 0 , function ( ) {
171
+ server . listen ( common . mustCall ( function ( ) {
160
172
const options = {
161
- port : this . address ( ) . port ,
173
+ port : server . address ( ) . port ,
162
174
allowHalfOpen : true ,
163
175
rejectUnauthorized : false
164
176
} ;
@@ -167,30 +179,32 @@ test(function serverResponseTimeoutWithPipeline(cb) {
167
179
c . write ( 'GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n' ) ;
168
180
c . write ( 'GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n' ) ;
169
181
} ) ;
170
- } ) ;
182
+ } ) ) ;
171
183
} ) ;
172
184
173
185
test ( function idleTimeout ( cb ) {
174
- const server = https . createServer ( serverOptions ,
175
- common . mustCall ( function ( req , res ) {
176
- req . on ( 'timeout' , common . mustNotCall ( ) ) ;
177
- res . on ( 'timeout' , common . mustNotCall ( ) ) ;
178
- res . end ( ) ;
179
- } ) ) ;
180
- server . setTimeout ( 50 , common . mustCall ( function ( socket ) {
186
+ const server = https . createServer (
187
+ serverOptions ,
188
+ common . mustCall ( function ( req , res ) {
189
+ req . on ( 'timeout' , common . mustNotCall ( ) ) ;
190
+ res . on ( 'timeout' , common . mustNotCall ( ) ) ;
191
+ res . end ( ) ;
192
+ } ) ) ;
193
+ const s = server . setTimeout ( 50 , common . mustCall ( function ( socket ) {
181
194
socket . destroy ( ) ;
182
195
server . close ( ) ;
183
196
cb ( ) ;
184
197
} ) ) ;
185
- server . listen ( 0 , function ( ) {
198
+ assert . ok ( s instanceof https . Server ) ;
199
+ server . listen ( common . mustCall ( function ( ) {
186
200
const options = {
187
- port : this . address ( ) . port ,
201
+ port : server . address ( ) . port ,
188
202
allowHalfOpen : true ,
189
203
rejectUnauthorized : false
190
204
} ;
191
205
tls . connect ( options , function ( ) {
192
206
this . write ( 'GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n' ) ;
193
207
// Keep-Alive
194
208
} ) ;
195
- } ) ;
209
+ } ) ) ;
196
210
} ) ;
0 commit comments