summaryrefslogtreecommitdiff
path: root/ext/fetch/23_request.js
AgeCommit message (Collapse)Author
2024-11-08feat(ext/http): abort event when request is cancelled (#26781)Divy Srivastava
```js Deno.serve(async (req) => { const { promise, resolve } = Promise.withResolvers<void>(); req.signal.addEventListener("abort", () => { resolve(); }); await promise; return new Response("Ok"); }); ```
2024-11-07feat(ext/http): abort signal when request is cancelled (#26761)Divy Srivastava
Closes https://github.com/denoland/deno/issues/21653
2024-09-18refactor(ext): align error messages (#25496)Ian Bull
Aligns the error messages in the ext/http and a few messages in the ext/fetch folder to be in-line with the Deno style guide. This change-set also removes some unnecessary checks in the 00_serve.ts. These options were recently removed, so it doesn't make sense to check for them anymore. https://github.com/denoland/deno/issues/25269
2024-05-23fix(runtime): use more null proto objects (#23921)Luca Casonato
This is a primordialization effort to improve resistance against users tampering with the global `Object` prototype. --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2024-04-29fix(ext/http): ensure signal is created iff requested (#23601)Matt Mastracci
This correctly creates the `AbortSignal` regardless of when we request it. If the signal is requested after the request has completed, the signal is created in the aborted state. Using GC counts, we can see a reduction in object creation: This PR: 440 deno 1.42.4: 1650 deno 1.43.0+b02ffec: 874
2024-04-25perf(ext/http): recover memory for serve and optimize AbortController (#23559)Matt Mastracci
Max rps without a signal is unchanged, however we can drastically reduce memory usage by not creating the signal until needed, and we can optimize the rps in the case where the signal is created. With a quick memory benchmark, it looks like this helps pretty drastically with # of GCs when benchmarking w/wrk: - 1.42.4: 1763 - canary: 1093 - this patch: 874 This branch: ``` Running 10s test @ http://localhost:8080/ 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 87.33us 439.95us 20.68ms 99.67% Req/Sec 66.70k 6.39k 74.11k 83.66% 1340255 requests in 10.10s, 191.73MB read Requests/sec: 132696.90 Transfer/sec: 18.98MB cpu: Apple M2 Pro runtime: deno 1.43.0 (aarch64-apple-darwin) file:///Users/matt/Documents/scripts/bench_request.js benchmark time (avg) iter/s (min … max) p75 p99 p995 ----------------------------------------------------------------------------------------------- ----------------------------- newRequest 986.5 ns/iter 1,013,682.6 (878.2 ns … 1.18 µs) 1.01 µs 1.18 µs 1.18 µs newAbortController 18 ns/iter 55,541,104.1 (15.6 ns … 42.62 ns) 17.71 ns 25.05 ns 26.27 ns newAbortControllerSignal 18.66 ns/iter 53,578,966.7 (16.49 ns … 32.16 ns) 18.71 ns 25.67 ns 26.39 ns newAbortControllerSignalOnAbort 106.49 ns/iter 9,390,164.9 (97.87 ns … 120.61 ns) 108.6 ns 114.24 ns 115.89 ns newAbortControllerSignalAddEventListener 86.92 ns/iter 11,504,880.2 (81.88 ns … 103.15 ns) 90 ns 98.28 ns 99.55 ns newAbortControllerSignalOnAbortNoListener 3.01 µs/iter 331,964.4 (2.97 µs … 3.1 µs) 3.06 µs 3.1 µs 3.1 µs newAbortControllerSignalOnAbortAbort 3.26 µs/iter 306,662.6 (3.22 µs … 3.36 µs) 3.27 µs 3.36 µs 3.36 µs ``` Latest canary: ``` Running 10s test @ http://localhost:8080/ 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 72.86us 71.23us 4.47ms 99.05% Req/Sec 64.66k 5.54k 72.48k 82.18% 1299015 requests in 10.10s, 185.83MB read Requests/sec: 128616.02 Transfer/sec: 18.40MB cpu: Apple M2 Pro runtime: deno 1.43.0+bc4aa5f (aarch64-apple-darwin) file:///Users/matt/Documents/scripts/bench_request.js benchmark time (avg) iter/s (min … max) p75 p99 p995 ----------------------------------------------------------------------------------------------- ----------------------------- newRequest 1.25 µs/iter 800,005.2 (1.01 µs … 4.18 µs) 1.16 µs 4.18 µs 4.18 µs newAbortController 18.56 ns/iter 53,868,204.3 (16.04 ns … 38.73 ns) 18.38 ns 26.1 ns 26.63 ns newAbortControllerSignal 18.72 ns/iter 53,430,746.1 (16.13 ns … 36.71 ns) 18.71 ns 26.19 ns 26.98 ns newAbortControllerSignalOnAbort 193.91 ns/iter 5,156,992.4 (184.25 ns … 211.41 ns) 194.96 ns 207.87 ns 209.4 ns newAbortControllerSignalAddEventListener 171.45 ns/iter 5,832,569.2 (153 ns … 182.03 ns) 176.17 ns 180.75 ns 181.05 ns newAbortControllerSignalOnAbortNoListener 3.07 µs/iter 326,263.3 (2.98 µs … 3.17 µs) 3.08 µs 3.17 µs 3.17 µs newAbortControllerSignalOnAbortAbort 3.32 µs/iter 301,344.6 (3.29 µs … 3.4 µs) 3.33 µs 3.4 µs 3.4 µs ```
2024-03-10chore: replace 'call' to 'execute' in error messages (#22579)Kenta Moriuchi
Since both "call" and "execute" were used in error messages, I replaced them with "execute," which is more used.
2024-02-18BREAKING(unstable): remove `Deno.HttpClient.rid` (#22075)Asher Gomez
As part of ongoing works to make `rid` private. --------- Co-authored-by: Matt Mastracci <matthew@mastracci.com>
2024-01-10refactor: use `core.ensureFastOps()` (#21888)Kenta Moriuchi
2024-01-01chore: update copyright to 2024 (#21753)David Sherret
2023-12-07refactor: pull 'core', 'internals', 'primordials' from ES module (#21462)Bartek Iwańczuk
This commit refactors how we access "core", "internals" and "primordials" objects coming from `deno_core`, in our internal JavaScript code. Instead of capturing them from "globalThis.__bootstrap" namespace, we import them from recently added "ext:core/mod.js" file.
2023-11-19fix(ext,runtime): add missing custom inspections (#21219)Kenta Moriuchi
2023-11-13feat(ext/web): add `AbortSignal.any()` (#21087)Kenta Moriuchi
Fixes #18944
2023-10-10fix(ext/web): writability of `ReadableStream.from` (#20836)Luca Casonato
Fixes a WPT in `URL` and `ReadableStream`. Some unrelated WPT expectation changes due to WPT update.
2023-09-21perf(ext/fetch): use new instead of createBranded (#20624)Marcos Casagrande
This PR optimizes `fromInner*` methods of `Request` / `Header` / `Response` used by `Deno.serve` and `fetch` by using `new` instead of `ObjectCreate` from `createBranded`. The "brand" is created by passing `webidl.brand` to the constructor instead. https://github.com/denoland/deno/blob/142449ecab20006c5cfd15462814650596bc034d/ext/webidl/00_webidl.js#L1001-L1005 ### Benchmark ```js const createBranded = Symbol("create branded"); const brand = Symbol("brand"); class B { constructor(init) { if (init === createBranded) { this[brand] = brand; } } } Deno.bench("Object.create(protoype)", () => { Object.create(B.prototype); }); Deno.bench("new Class", () => { new B(createBranded); }); ``` ``` cpu: 13th Gen Intel(R) Core(TM) i9-13900H runtime: deno 1.37.0 (x86_64-unknown-linux-gnu) benchmark time (avg) iter/s (min … max) p75 p99 p995 ----------------------------------------------------------------------------- ----------------------------- Object.create(protoype) 8.74 ns/iter 114,363,610.3 (7.32 ns … 26.02 ns) 8.65 ns 13.39 ns 14.47 ns new Class 3.05 ns/iter 328,271,012.2 (2.78 ns … 9.1 ns) 3.06 ns 3.46 ns 3.5 ns ```
2023-08-12perf(ext/request): optimize validate and normalize HTTP method (#20143)Marcos Casagrande
This PR optimizes `Request` constructor init method step. It doubles the speed for known lowercased methods. I also added `PATCH` to known methods **this patch** ``` benchmark time (avg) iter/s (min … max) p75 p99 p995 ---------------------------------------------------------------------------- ----------------------------- method: GET 1.49 µs/iter 669,336.9 (1.35 µs … 2.02 µs) 1.54 µs 2.02 µs 2.02 µs method: PATCH 1.85 µs/iter 540,921.5 (1.65 µs … 2.02 µs) 1.91 µs 2.02 µs 2.02 µs method: get 1.49 µs/iter 669,067.9 (1.28 µs … 1.69 µs) 1.55 µs 1.69 µs 1.69 µs ``` **main** ``` cpu: 13th Gen Intel(R) Core(TM) i9-13900H runtime: deno 1.36.1 (x86_64-unknown-linux-gnu) benchmark time (avg) iter/s (min … max) p75 p99 p995 ---------------------------------------------------------------------------- ----------------------------- method: GET 1.5 µs/iter 665,232.3 (1.3 µs … 2.02 µs) 1.54 µs 2.02 µs 2.02 µs method: PATCH 2.47 µs/iter 404,052.7 (2.06 µs … 4.05 µs) 2.51 µs 4.05 µs 4.05 µs method: get 3 µs/iter 333,277.2 (2.72 µs … 4.04 µs) 3.05 µs 4.04 µs 4.04 µs ``` ```js Deno.bench("method: GET", () => { const r = new Request("https://deno.land", { method: "GET", }); }); Deno.bench("method: PATCH", () => { const r = new Request("https://deno.land", { method: "PATCH", body: '{"foo": "bar"}', }); }); Deno.bench("method: get", () => { const r = new Request("https://deno.land", { method: "get", }); }); ```
2023-08-12perf(ext/request): optimize Request constructor (#20141)Marcos Casagrande
This PR optimizes `Request` constructor when `init` is not empty. This path is also used by `fetch` when `options` argument is used ```js fetch("https://deno.land", { method: "POST", body: 'land' }); ``` - Removed 3 extra calls to `headerListFromHeaders` - Avoid `Object.keys` & `headerList` clone if `init.headers` is set - Only empty `headersList` (`.splice`) if it's not already empty. ## Benchmarks **this patch** ``` cpu: 13th Gen Intel(R) Core(TM) i9-13900H runtime: deno 1.36.1 (x86_64-unknown-linux-gnu) benchmark time (avg) iter/s (min … max) p75 p99 p995 ----------------------------------------------------------------------------- ----------------------------- Request without headers 1.86 µs/iter 536,440.7 (1.67 µs … 2.76 µs) 1.89 µs 2.76 µs 2.76 µs Request with headers 1.96 µs/iter 509,440.5 (1.83 µs … 2.17 µs) 1.99 µs 2.17 µs 2.17 µs ``` **main** ``` cpu: 13th Gen Intel(R) Core(TM) i9-13900H runtime: deno 1.36.1 (x86_64-unknown-linux-gnu) benchmark time (avg) iter/s (min … max) p75 p99 p995 ----------------------------------------------------------------------------- ----------------------------- Request without headers 1.96 µs/iter 510,201.5 (1.81 µs … 2.64 µs) 2 µs 2.64 µs 2.64 µs Request with headers 2.03 µs/iter 493,526.6 (1.84 µs … 2.31 µs) 2.08 µs 2.31 µs 2.31 µs ``` ```js Deno.bench("Request without headers", () => { const r = new Request("https://deno.land", { method: "POST", body: '{"foo": "bar"}', }); }); Deno.bench("Request with headers", () => { const r = new Request("https://deno.land", { method: "POST", body: '{"foo": "bar"}', headers: { "Content-Type": "application/json", }, }); }); ```
2023-07-30fix(Deno.serve): accessing .url on cloned request throws (#19869)Felipe Baltor
This PR fixes #19818. The problem was that the new InnerRequest class does not initialize the fields urlList and urlListProcessed that are used during a request clone. The solution aims to be straightforward by simply initializing the missing properties during the clone process. I also implemented a "cache" to the url getter of the new InnerRequest, avoiding the cost of calling op_http_get_request_method_and_url.
2023-06-05perf: optimize RegExp usage in JS (#19364)Bartek Iwańczuk
Towards https://github.com/denoland/deno/issues/19330 Shows about 1% improvement in the HTTP benchmark.
2023-05-01fix(core): Use primordials for methods (#18839)Kenta Moriuchi
I would like to get this change into Deno before merging https://github.com/denoland/deno_lint/pull/1152
2023-05-01refactor(webidl): move prefix & context out of converters options bag (#18931)Leo Kettmeir
2023-04-30refactor: remove ext/console/01_colors.js (#18927)Leo Kettmeir
2023-04-20refactor(ext/webidl): remove option bags from "makeException" (#18679)Bartek Iwańczuk
Creating these options bags is more costly than passing arguments one-by-one. Especially since `prefix` and `context` are passed to all functions.
2023-04-12refactor(ext/webidl): remove object from 'requiredArguments' (#18674)Bartek Iwańczuk
This should produce a little less garbage and using an object here wasn't really required. --------- Co-authored-by: Aapo Alasuutari <aapo.alasuutari@gmail.com> Co-authored-by: Leo Kettmeir <crowlkats@toaxl.com>
2023-04-04refactor: remove remaining references to "flash" server (#18580)Bartek Iwańczuk
Follow up to https://github.com/denoland/deno/pull/18578 We will need to do another pass cleaning up `ext/fetch/23_request.js`
2023-03-08refactor: rename InternalModuleLoader to ExtModuleLoader, use ext: scheme ↵Bartek Iwańczuk
for snapshotted modules (#18041) This commit renames "deno_core::InternalModuleLoader" to "ExtModuleLoader" and changes the specifiers used by the modules loaded from this loader to "ext:". "internal:" scheme was really ambiguous and it's more characters than "ext:", which should result in slightly smaller snapshot size. Closes https://github.com/denoland/deno/issues/18020
2023-02-07 refactor: remove prefix from include_js_files & use extension name (#17683)Leo Kettmeir
2023-02-07refactor: Use ES modules for internal runtime code (#17648)Leo Kettmeir
This PR refactors all internal js files (except core) to be written as ES modules. `__bootstrap`has been mostly replaced with static imports in form in `internal:[path to file from repo root]`. To specify if files are ESM, an `esm` method has been added to `Extension`, similar to the `js` method. A new ModuleLoader called `InternalModuleLoader` has been added to enable the loading of internal specifiers, which is used in all situations except when a snapshot is only loaded, and not a new one is created from it. --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-01-15fix(ext/fetch) Fix request clone error in flash server (#16174)Isaiah Gamble
2023-01-02chore: update copyright year to 2023 (#17247)David Sherret
Yearly tradition of creating extra noise in git.
2022-12-06fix(ext/fetch): new Request should soft clone (#16869)Luca Casonato
Previously the inner request object of the original and the new request were the same, causing the requests to be entangled and mutable changes to one to be visible to the other. This fixes that.
2022-10-03refactor(ext/fetch): avoid extra headers copy in .clone (#16130)Marcos Casagrande
2022-08-18feat(ext/flash): An optimized http/1.1 server (#15405)Divy Srivastava
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com> Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl> Co-authored-by: crowlkats <crowlkats@toaxl.com> Co-authored-by: Ryan Dahl <ry@tinyclouds.org>
2022-08-17refactor(fetch/request): use callback for url and method (#15483)Leo Kettmeir
2022-07-12fix(ext/http): reading headers with ongoing body reader (#15161)Divy Srivastava
2022-07-04perf(ext/http): lazy load headers (#15055)Divy Srivastava
2022-03-25chore(ext): fix typo in ext/webgpu, ext/fetch (#14106)apeltop
2022-03-20cleanup(web, fetch): dedupe minesniff / "extract a MIME type" algorithm (#14044)Andreu Botella
Closes #14002
2022-02-07refactor: update runtime code for primordial check for iterators (#13510)Bartek Iwańczuk
2022-02-01refactor: primordials for instanceof (#13527)Bartek Iwańczuk
2022-01-27Revert "refactor: update runtime code for primordial checks for "instanceof" ↵Bartek Iwańczuk
(#13497)" (#13511) This reverts commit 884143218fad0e18f7553aaf079d52de703f7601.
2022-01-27refactor: update runtime code for primordial checks for "instanceof" (#13497)Bartek Iwańczuk
2022-01-07chore: update copyright to 2022 (#13306)Ryan Dahl
Co-authored-by: Erfan Safari <erfanshield@outlook.com>
2021-11-23revert: store header keys lower case internally (#12837)Luca Casonato
This reverts commit 49ec3d10ad90851f4d28274a3f0fe96c642204ac.
2021-09-27perf(fetch): optimize newInnerRequest blob url check (#12245)Aaron O'Mullan
Avoid "blob:" prefix check on requests built in the http module since those can never be blob objects Reduces cost of `newInnerRequest()` from 20ms to 0.1ms in my profiled run on ~2.5M reqs
2021-09-27refactor(fetch/Request): inline defaultInnerRequest (#12241)Aaron O'Mullan
Similar to #12235
2021-09-25perf(ext/fetch): Use the WebIDL conversion to DOMString rather than ↵Luis Malheiro
USVString for Response constructor (#12201)
2021-09-25fix(ext/webidl): correctly apply [SymbolToStringTag] to interfaces (#11851)李瑞丰
Co-authored-by: Luca Casonato <hello@lcas.dev> Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
2021-09-23perf(ext/fetch): skip USVString webidl conv on string constructor (#12168)Aaron O'Mullan
* perf(ext/fetch): skip USVString webidl conv on string constructor * Rename webidl convert to RequestInfo_DOMString To disambiguate and hint that it normalizes to DOMString instead of USVString since DOMString => USVString is handled by `op_url_parse` when calling `new URL(...)`
2021-09-08fix: a `Request` whose URL is a revoked blob URL should still fetch (#11947)Andreu Botella
In the spec, a URL record has an associated "blob URL entry", which for `blob:` URLs is populated during parsing to contain a reference to the `Blob` object that backs that object URL. It is this blob URL entry that the `fetch` API uses to resolve an object URL. Therefore, since the `Request` constructor parses URL inputs, it will have an associated blob URL entry which will be used when fetching, even if the object URL has been revoked since the construction of the `Request` object. (The `Request` constructor takes the URL as a string and parses it, so the object URL must be live at the time it is called.) This PR adds a new `blobFromObjectUrl` JS function (backed by a new `op_blob_from_object_url` op) that, if the URL is a valid object URL, returns a new `Blob` object whose parts are references to the same Rust `BlobPart`s used by the original `Blob` object. It uses this function to add a new `blobUrlEntry` field to inner requests, which will be `null` or such a `Blob`, and then uses `Blob.prototype.stream()` as the response's body. As a result of this, the `blob:` URL resolution from `op_fetch` is now useless, and has been removed.