@@ -6,6 +6,7 @@ import { baseUrl } from './main';
6
6
const isomorphicFetch = require ( 'isomorphic-fetch' ) ;
7
7
const isNode = typeof process === 'object' && process . versions && ! ! process . versions . node ;
8
8
const nodeHttps = isNode && require ( 'https' ) ;
9
+ const isHttpsRegex = / ^ h t t p s \: / ;
9
10
10
11
function issueRequest ( baseUrl : string , req : string | Request , init ?: RequestInit ) : Promise < any > {
11
12
const reqUrl = ( req instanceof Request ) ? req . url : req ;
@@ -30,11 +31,11 @@ function issueRequest(baseUrl: string, req: string | Request, init?: RequestInit
30
31
` ) ;
31
32
}
32
33
33
- init = applyHttpsAgentPolicy ( init , isRelativeUrl ) ;
34
+ init = applyHttpsAgentPolicy ( init , isRelativeUrl , baseUrl ) ;
34
35
return isomorphicFetch ( req , init ) ;
35
36
}
36
37
37
- function applyHttpsAgentPolicy ( init : RequestInit , isRelativeUrl : boolean ) : RequestInit {
38
+ function applyHttpsAgentPolicy ( init : RequestInit , isRelativeUrl : boolean , baseUrl : string ) : RequestInit {
38
39
// HTTPS is awkward in Node because it uses a built-in list of CAs, rather than recognizing
39
40
// the OS's system-level CA list. There are dozens of issues filed against Node about this,
40
41
// but still (as of v8.0.0) no resolution besides manually duplicating your CA config.
@@ -54,12 +55,15 @@ function applyHttpsAgentPolicy(init: RequestInit, isRelativeUrl: boolean): Reque
54
55
// for 'agent' (which would let you set up other HTTPS-handling policies), then we automatically
55
56
// disable cert verification for that request.
56
57
if ( isNode && isRelativeUrl ) {
57
- const hasAgentConfig = init && ( 'agent' in init ) ;
58
- if ( ! hasAgentConfig ) {
59
- const agentForRequest = new ( nodeHttps . Agent ) ( { rejectUnauthorized : false } ) ;
58
+ const isHttps = baseUrl && isHttpsRegex . test ( baseUrl ) ;
59
+ if ( isHttps ) {
60
+ const hasAgentConfig = init && ( 'agent' in init ) ;
61
+ if ( ! hasAgentConfig ) {
62
+ const agentForRequest = new ( nodeHttps . Agent ) ( { rejectUnauthorized : false } ) ;
60
63
61
- init = init || { } ;
62
- ( init as any ) . agent = agentForRequest ;
64
+ init = init || { } ;
65
+ ( init as any ) . agent = agentForRequest ;
66
+ }
63
67
}
64
68
}
65
69
0 commit comments