From c84ddd68e269381e3d2a955e7f3831a89b9a07e9 Mon Sep 17 00:00:00 2001 From: Mitchell Wills Date: Tue, 8 Oct 2019 10:11:54 -0700 Subject: [PATCH] feat(TypeScript): agent can now be passed as builder method, rather than agent instance --- src/common.ts | 5 +++-- src/gaxios.ts | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/common.ts b/src/common.ts index 649037f6..d17da402 100644 --- a/src/common.ts +++ b/src/common.ts @@ -12,7 +12,8 @@ // limitations under the License. import {AbortSignal} from 'abort-controller'; -import {Agent} from 'https'; +import {Agent} from 'http'; +import {URL} from 'url'; // tslint:disable no-any @@ -84,7 +85,7 @@ export interface GaxiosOptions { timeout?: number; onUploadProgress?: (progressEvent: any) => void; responseType?: 'arraybuffer' | 'blob' | 'json' | 'text' | 'stream'; - agent?: Agent; + agent?: Agent | ((parsedUrl: URL) => Agent); validateStatus?: (status: number) => boolean; retryConfig?: RetryConfig; retry?: boolean; diff --git a/src/gaxios.ts b/src/gaxios.ts index aba2fe7c..fdf5101d 100644 --- a/src/gaxios.ts +++ b/src/gaxios.ts @@ -12,7 +12,7 @@ // limitations under the License. import extend from 'extend'; -import {Agent} from 'https'; +import {Agent} from 'http'; import nodeFetch, {Response as NodeFetchResponse} from 'node-fetch'; import qs from 'querystring'; import stream from 'stream'; @@ -64,7 +64,10 @@ function loadProxy() { loadProxy(); export class Gaxios { - private agentCache = new Map(); + private agentCache = new Map< + string, + Agent | ((parsedUrl: url.URL) => Agent) + >(); /** * Default HTTP options that will be used for every HTTP request.