@@ -6,35 +6,31 @@ import { Agent as hsAgent, request as hsRequest, RequestOptions } from "https";
6
6
7
7
import { NODEJS_TIMEOUT_ERROR_CODES } from "./constants" ;
8
8
import { getTransformedHeaders } from "./get-transformed-headers" ;
9
+ import { setConnectionTimeout } from "./set-connection-timeout" ;
10
+ import { setSocketTimeout } from "./set-socket-timeout" ;
9
11
import { writeRequestBody } from "./write-request-body" ;
10
12
11
13
/**
12
14
* Represents the http options that can be passed to a node http client.
13
15
*/
14
16
export interface NodeHttpHandlerOptions {
15
17
/**
16
- * @deprecated Use {@link requestTimeout}
17
- *
18
- * Note:{@link NodeHttpHandler} will resolve request timeout via nullish coalescing the following fields:
19
- * {@link requestTimeout} ?? {@link connectionTimeout} ?? {@link socketTimeout} ?? {@link DEFAULT_REQUEST_TIMEOUT}
20
- *
21
18
* The maximum time in milliseconds that the connection phase of a request
22
19
* may take before the connection attempt is abandoned.
20
+ *
21
+ * Defaults to 0, which disables the timeout.
23
22
*/
24
23
connectionTimeout ?: number ;
25
24
26
25
/**
27
- * The maximum time in milliseconds that the connection phase of a request
28
- * may take before the connection attempt is abandoned .
26
+ * The number of milliseconds a request can take before automatically being terminated.
27
+ * Defaults to 0, which disables the timeout .
29
28
*/
30
29
requestTimeout ?: number ;
31
30
32
31
/**
33
32
* @deprecated Use {@link requestTimeout}
34
33
*
35
- * Note:{@link NodeHttpHandler} will resolve request timeout via nullish coalescing the following fields:
36
- * {@link requestTimeout} ?? {@link connectionTimeout} ?? {@link socketTimeout} ?? {@link DEFAULT_REQUEST_TIMEOUT}
37
- *
38
34
* The maximum time in milliseconds that a socket may remain idle before it
39
35
* is closed.
40
36
*/
@@ -45,9 +41,8 @@ export interface NodeHttpHandlerOptions {
45
41
}
46
42
47
43
interface ResolvedNodeHttpHandlerConfig {
48
- requestTimeout : number ;
44
+ requestTimeout ? : number ;
49
45
connectionTimeout ?: number ;
50
- socketTimeout ?: number ;
51
46
httpAgent : hAgent ;
52
47
httpsAgent : hsAgent ;
53
48
}
@@ -82,8 +77,7 @@ export class NodeHttpHandler implements HttpHandler {
82
77
83
78
return {
84
79
connectionTimeout,
85
- socketTimeout,
86
- requestTimeout : requestTimeout ?? connectionTimeout ?? socketTimeout ?? DEFAULT_REQUEST_TIMEOUT ,
80
+ requestTimeout : requestTimeout ?? socketTimeout ,
87
81
httpAgent : httpAgent || new hAgent ( { keepAlive, maxSockets } ) ,
88
82
httpsAgent : httpsAgent || new hsAgent ( { keepAlive, maxSockets } ) ,
89
83
} ;
@@ -142,11 +136,9 @@ export class NodeHttpHandler implements HttpHandler {
142
136
}
143
137
} ) ;
144
138
145
- const timeout : number = this . config ?. requestTimeout ?? DEFAULT_REQUEST_TIMEOUT ;
146
- req . setTimeout ( timeout , ( ) => {
147
- req . destroy ( ) ;
148
- reject ( Object . assign ( new Error ( `Connection timed out after ${ timeout } ms` ) , { name : "TimeoutError" } ) ) ;
149
- } ) ;
139
+ // wire-up any timeout logic
140
+ setConnectionTimeout ( req , reject , this . config . connectionTimeout ) ;
141
+ setSocketTimeout ( req , reject , this . config . requestTimeout ) ;
150
142
151
143
// wire-up abort logic
152
144
if ( abortSignal ) {
0 commit comments