diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2021-02-04 13:08:41 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-04 13:08:41 -0500 |
commit | 644a7ff2d70cbd8bfba4c87b75a047e79830c4b6 (patch) | |
tree | 8f9cbd0989cf91e9684b843735c632c902bbfc78 /op_crates/fetch | |
parent | 25b35be50dd59d00e126591dd24d06824e2c50cf (diff) |
fetch optimizations (#9402)
Release deno_fetch 0.20.2
Diffstat (limited to 'op_crates/fetch')
-rw-r--r-- | op_crates/fetch/26_fetch.js | 31 | ||||
-rw-r--r-- | op_crates/fetch/Cargo.toml | 2 |
2 files changed, 28 insertions, 5 deletions
diff --git a/op_crates/fetch/26_fetch.js b/op_crates/fetch/26_fetch.js index 52ae91e83..58e2cab85 100644 --- a/op_crates/fetch/26_fetch.js +++ b/op_crates/fetch/26_fetch.js @@ -682,6 +682,10 @@ const teeBody = Symbol("Body#tee"); + // fastBody and dontValidateUrl allow users to opt out of certain behaviors + const fastBody = Symbol("Body#fast"); + const dontValidateUrl = Symbol("dontValidateUrl"); + class Body { #contentType = ""; #size; @@ -730,6 +734,17 @@ return this.#stream; } + // Optimization that allows caller to bypass expensive ReadableStream. + [fastBody]() { + if (!this.#bodySource) { + return null; + } else if (!(this.#bodySource instanceof ReadableStream)) { + return bodyToArrayBuffer(this.#bodySource); + } else { + return this.body; + } + } + /** @returns {BodyInit | null} */ [teeBody]() { if (this.#stream || this.#bodySource instanceof ReadableStream) { @@ -991,10 +1006,16 @@ this.#headers = new Headers(input.headers); this.#credentials = input.credentials; } else { - const baseUrl = getLocationHref(); - this.#url = baseUrl != null - ? new URL(String(input), baseUrl).href - : new URL(String(input)).href; + // Constructing a URL just for validation is known to be expensive. + // dontValidateUrl allows one to opt out. + if (init[dontValidateUrl]) { + this.#url = input; + } else { + const baseUrl = getLocationHref(); + this.#url = baseUrl != null + ? new URL(String(input), baseUrl).href + : new URL(String(input)).href; + } } if (init && "method" in init && init.method) { @@ -1477,5 +1498,7 @@ Response, HttpClient, createHttpClient, + fastBody, + dontValidateUrl, }; })(this); diff --git a/op_crates/fetch/Cargo.toml b/op_crates/fetch/Cargo.toml index 4e6cb309c..a96775d71 100644 --- a/op_crates/fetch/Cargo.toml +++ b/op_crates/fetch/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_fetch" -version = "0.20.1" +version = "0.20.2" edition = "2018" description = "provides fetch Web API to deno_core" authors = ["the Deno authors"] |