node-fetch: allow agent to accept a function returning Agent (#36057)

* Allow Agent to accept a function

* Fix types

* string -> URL

* Update index.d.ts
This commit is contained in:
Steve Faulkner 2019-06-12 15:50:35 -04:00 committed by Ron Buckton
parent 17717b3957
commit 49e9bf98b3
2 changed files with 5 additions and 3 deletions

View File

@ -7,12 +7,13 @@
// Andrew Leedham <https://github.com/AndrewLeedham>
// Jason Li <https://github.com/JasonLi914>
// Brandon Wilson <https://github.com/wilsonianb>
// Steve Faulkner <https://github.com/southpolesteve>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import { Agent } from "http";
import { URLSearchParams } from "url";
import { URLSearchParams, URL } from "url";
import { AbortSignal } from "./externals";
export class Request extends Body {
@ -26,7 +27,7 @@ export class Request extends Body {
url: string;
// node-fetch extensions to the whatwg/fetch spec
agent?: Agent;
agent?: Agent | ((parsedUrl: URL) => Agent);
compress: boolean;
counter: number;
follow: number;

View File

@ -6,6 +6,7 @@ import fetch, {
Response,
FetchError
} from "node-fetch";
import { URL } from "url";
import { Agent } from "http";
function test_fetchUrlWithOptions() {
@ -73,7 +74,7 @@ function test_fetchUrlWithRequestObject() {
);
const timeout: number = request.timeout;
const size: number = request.size;
const agent: Agent | undefined = request.agent;
const agent: Agent | ((parsedUrl: URL) => Agent) | undefined = request.agent;
const protocol: string = request.protocol;
handlePromise(fetch(request));