@@ -31,33 +31,9 @@ export class NodeHttpHandler implements HttpHandler<Readable, NodeHttpOptions> {
31
31
32
32
handle (
33
33
request : HttpRequest < Readable > ,
34
- options : HttpHandlerOptions
34
+ { abortSignal } : HttpHandlerOptions
35
35
) : Promise < HttpResponse < Readable > > {
36
- // determine which http(s) client to use
37
- const isSSL = request . protocol === "https:" ;
38
- const httpClient = isSSL ? https : http ;
39
-
40
- let path = request . path ;
41
- if ( request . query ) {
42
- const queryString = buildQueryString ( request . query ) ;
43
- if ( queryString ) {
44
- path += `?${ queryString } ` ;
45
- }
46
- }
47
-
48
- const nodeHttpsOptions : https . RequestOptions = {
49
- headers : request . headers ,
50
- host : request . hostname ,
51
- method : request . method ,
52
- path : path ,
53
- port : request . port ,
54
- agent : isSSL ? this . httpsAgent : this . httpAgent
55
- } ;
56
-
57
36
return new Promise ( ( resolve , reject ) => {
58
- const abortSignal = options && options . abortSignal ;
59
- const { connectionTimeout, socketTimeout } = this . httpOptions ;
60
-
61
37
// if the request was already aborted, prevent doing extra work
62
38
if ( abortSignal && abortSignal . aborted ) {
63
39
const abortError = new Error ( "Request aborted" ) ;
@@ -66,8 +42,20 @@ export class NodeHttpHandler implements HttpHandler<Readable, NodeHttpOptions> {
66
42
return ;
67
43
}
68
44
45
+ // determine which http(s) client to use
46
+ const isSSL = request . protocol === "https:" ;
47
+ const queryString = buildQueryString ( request . query || { } ) ;
48
+ const nodeHttpsOptions : https . RequestOptions = {
49
+ headers : request . headers ,
50
+ host : request . hostname ,
51
+ method : request . method ,
52
+ path : queryString ? `${ request . path } ?${ queryString } ` : request . path ,
53
+ port : request . port ,
54
+ agent : isSSL ? this . httpsAgent : this . httpAgent
55
+ } ;
56
+
69
57
// create the http request
70
- const req = ( httpClient as typeof http ) . request ( nodeHttpsOptions , res => {
58
+ const req = ( isSSL ? https : http ) . request ( nodeHttpsOptions , res => {
71
59
const httpResponse : HttpResponse < Readable > = {
72
60
statusCode : res . statusCode || - 1 ,
73
61
headers : getTransformedHeaders ( res . headers ) ,
@@ -79,8 +67,8 @@ export class NodeHttpHandler implements HttpHandler<Readable, NodeHttpOptions> {
79
67
req . on ( "error" , reject ) ;
80
68
81
69
// wire-up any timeout logic
82
- setConnectionTimeout ( req , reject , connectionTimeout ) ;
83
- setSocketTimeout ( req , reject , socketTimeout ) ;
70
+ setConnectionTimeout ( req , reject , this . httpOptions . connectionTimeout ) ;
71
+ setSocketTimeout ( req , reject , this . httpOptions . socketTimeout ) ;
84
72
85
73
// wire-up abort logic
86
74
if ( abortSignal ) {
0 commit comments