diff options
author | Axetroy <axetroy.dev@gmail.com> | 2019-12-14 20:49:30 +0800 |
---|---|---|
committer | Ry Dahl <ry@tinyclouds.org> | 2019-12-14 20:49:30 +0800 |
commit | 83f95fb8dfaed42eee3e1e0cd3a6e9b94f05ef2d (patch) | |
tree | d7d8db6caa3f47bb598c83cb4e489d1272840d35 /cli/js/fetch.ts | |
parent | 7e116dd70d7c194f2967d64e7700aae0bb17100f (diff) |
fetch support URL instance as input (#3496)
Diffstat (limited to 'cli/js/fetch.ts')
-rw-r--r-- | cli/js/fetch.ts | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/cli/js/fetch.ts b/cli/js/fetch.ts index 24daf7f9c..f5fb8e6bb 100644 --- a/cli/js/fetch.ts +++ b/cli/js/fetch.ts @@ -13,6 +13,7 @@ import * as io from "./io.ts"; import { read, close } from "./files.ts"; import { Buffer } from "./buffer.ts"; import { FormData } from "./form_data.ts"; +import { URL } from "./url.ts"; import { URLSearchParams } from "./url_search_params.ts"; import * as dispatch from "./dispatch.ts"; import { sendAsync } from "./dispatch_json.ts"; @@ -367,7 +368,7 @@ async function sendFetchReq( /** Fetch a resource from the network. */ export async function fetch( - input: domTypes.Request | string, + input: domTypes.Request | URL | string, init?: domTypes.RequestInit ): Promise<Response> { let url: string; @@ -377,8 +378,8 @@ export async function fetch( let redirected = false; let remRedirectCount = 20; // TODO: use a better way to handle - if (typeof input === "string") { - url = input; + if (typeof input === "string" || input instanceof URL) { + url = typeof input === "string" ? (input as string) : (input as URL).href; if (init != null) { method = init.method || null; if (init.headers) { |