1- import { join , promiseTimeout , scopedLogger , utf8ToBase64 } from "@hpcc-js/util" ;
1+ import { join , promiseTimeout , root , scopedLogger , utf8ToBase64 } from "@hpcc-js/util" ;
22
33const logger = scopedLogger ( "comms/connection.ts" ) ;
44
@@ -154,20 +154,12 @@ function doFetch(opts: IOptions, action: string, requestInit: RequestInit, heade
154154 headers : headersInit
155155 } ;
156156
157- if ( fetch [ "__setGlobalDispatcher" ] ) {
158- fetch [ "__setGlobalDispatcher" ] ( fetch [ "__defaultAgent" ] ) ;
159- }
160-
161157 if ( opts . baseUrl . indexOf ( "https:" ) === 0 ) {
162158 // NodeJS / node-fetch only ---
163- if ( opts . rejectUnauthorized === false && fetch [ "__rejectUnauthorizedAgent" ] ) {
164- if ( fetch [ "__setGlobalDispatcher" ] ) {
165- fetch [ "__setGlobalDispatcher" ] ( fetch [ "__rejectUnauthorizedAgent" ] ) ;
166- } else {
167- requestInit [ "agent" ] = fetch [ "__rejectUnauthorizedAgent" ] ;
168- }
169- } else if ( fetch [ "__trustwaveAgent" ] ) {
170- requestInit [ "agent" ] = fetch [ "__trustwaveAgent" ] ;
159+ if ( opts . rejectUnauthorized === false && root . __hpcc_rejectUnauthorizedAgent ) {
160+ requestInit [ "dispatcher" ] = root . __hpcc_rejectUnauthorizedAgent ;
161+ } else if ( root . __hpcc_trustwaveAgent ) {
162+ requestInit [ "agent" ] = root . __hpcc_trustwaveAgent ;
171163 }
172164 }
173165
@@ -178,12 +170,13 @@ function doFetch(opts: IOptions, action: string, requestInit: RequestInit, heade
178170 throw new Error ( response . statusText ) ;
179171 }
180172
181- return promiseTimeout ( opts . timeoutSecs ! * 1000 , fetch ( join ( opts . baseUrl , action ) , requestInit )
173+ const fetchOverride = root . __hpcc_undiciFetch ?? fetch ;
174+ return promiseTimeout ( opts . timeoutSecs ! * 1000 , fetchOverride ( join ( opts . baseUrl , action ) , requestInit )
182175 . then ( handleResponse )
183176 . catch ( e => {
184177 // Try again with the opposite credentials mode ---
185178 requestInit . credentials = ! _omitMap [ opts . baseUrl ] ? "omit" : "include" ;
186- return fetch ( join ( opts . baseUrl , action ) , requestInit )
179+ return fetchOverride ( join ( opts . baseUrl , action ) , requestInit )
187180 . then ( handleResponse )
188181 . then ( responseBody => {
189182 _omitMap [ opts . baseUrl ] = ! _omitMap [ opts . baseUrl ] ; // The "opposite" credentials mode is known to work ---
0 commit comments