summaryrefslogtreecommitdiff
path: root/ext/fetch/lib.rs
AgeCommit message (Collapse)Author
2024-11-18feat(ext/fetch): Make fetch client parameters configurable (#26909)Yusuke Tanaka
This commit makes HTTP client parameters used in `fetch` API configurable on the extension initialization via a callback `client_builder_hook` that users can provide. The main motivation behind this change is to allow `deno_fetch` users to tune the HTTP/2 client to suit their needs, although Deno CLI users will not benefit from it as no JavaScript interface is exposed to set these parameters currently. It is up to users whether to provide a hook function. If not provided, the default configuration from hyper crate will be used. Ref #26785
2024-11-15feat(ext/fetch): allow embedders to use `hickory_dns_resolver` instead of ↵Sahand Akbarzadeh
default `GaiResolver` (#26740) Allows embedders to use `hickory-dns-resolver` instead of threaded "getaddrinfo" resolver in the `fetch()` implementation.
2024-11-04refactor(runtime/permissions): use concrete error types (#26464)Leo Kettmeir
2024-10-19refactor(ext/fetch): use concrete error types (#26220)Leo Kettmeir
2024-09-16refactor(permissions): split up Descriptor into Allow, Deny, and Query (#25508)David Sherret
This makes the permission system more versatile.
2024-09-04chore(ext/fetch): remove op_fetch_response_upgrade (#25421)Satya Rohith
2024-09-04refactor(ext/fetch): align error messages (#25374)Ian Bull
Aligns the error messages in the ext/fetch folder to be in-line with the Deno style guide. https://github.com/denoland/deno/issues/25269
2024-08-08fix(ext/fetch): include TCP src/dst socket info in error messages (#24939)Yusuke Tanaka
This commit makes `fetch` error messages include source and destination TCP socket info i.e. port number and IP address for better debuggability. Closes #24922
2024-08-07fix(ext/fetch): include URL and error details on fetch failures (#24910)Yusuke Tanaka
This commit improves error messages that `fetch` generates on failure. Fixes #24835
2024-07-24fix(ext/fetch): respect authority from URL (#24705)Bartek Iwańczuk
This commit fixes handling of "authority" in the URL by properly sending "Authorization Basic..." header in `fetch` API. This is a regression from https://github.com/denoland/deno/pull/24593 Fixes https://github.com/denoland/deno/issues/24697 CC @seanmonstar
2024-07-24fix(ext/fetch): use correct ALPN to proxies (#24696)Sean McArthur
Sending ALPN to a proxy, and then when tunneling, requires better juggling of TLS configs. This improves the choice of TLS config in the proxy connector, based on what reqwest does. It also includes some `ext/fetch/tests.rs` that check the different combinations. Fixes #24632 Fixes #24691
2024-07-18Reland "refactor(fetch): reimplement fetch with hyper instead of reqwest" ↵Bartek Iwańczuk
(#24593) Originally landed in https://github.com/denoland/deno/commit/f6fd6619e708a515831f707438368d81b0c9aa56. Reverted in https://github.com/denoland/deno/pull/24574. This reland contains a fix that sends "Accept: */*" header for calls made from "FileFetcher". Absence of this header made downloading source code from JSR broken. This is tested by ensuring this header is present in the test server that servers JSR packages. --------- Co-authored-by: Sean McArthur <sean@seanmonstar.com>
2024-07-13Revert "refactor(fetch): reimplement fetch with hyper instead of reqwest ↵Ryan Dahl
(#24237)" (#24574) This reverts commit f6fd6619e708a515831f707438368d81b0c9aa56. I'm seeing a difference between canary and 1.45.2. In `deno-docs/reference_gen` I can't download dax when running `deno task types` ``` ~/src/deno-docs/reference_gen# deno upgrade --canary Looking up latest canary version Found latest version f6fd6619e708a515831f707438368d81b0c9aa56 Downloading https://dl.deno.land/canary/f6fd6619e708a515831f707438368d81b0c9aa56/deno-aarch64-apple-darwin.zip Deno is upgrading to version f6fd6619e708a515831f707438368d81b0c9aa56 Archive: /var/folders/9v/kys6gqns6kl8nksyn4l1f9v40000gn/T/.tmpb5lDnq/deno.zip inflating: deno Upgraded successfully ~/src/deno-docs/reference_gen# deno -v deno 1.45.2+f6fd661 ~/src/deno-docs/reference_gen# rm -rf /Users/ry/Library/Caches/deno ~/src/deno-docs/reference_gen# deno task types Task types deno task types:deno && deno task types:node Task types:deno deno run --allow-read --allow-write --allow-run --allow-env --allow-sys deno-docs.ts error: JSR package manifest for '@david/dax' failed to load. expected value at line 1 column 1 at file:///Users/ry/src/deno-docs/reference_gen/deno-docs.ts:2:15 ~/src/deno-docs/reference_gen# deno upgrade --version 1.45.2 Downloading https://github.com/denoland/deno/releases/download/v1.45.2/deno-aarch64-apple-darwin.zip Deno is upgrading to version 1.45.2 Archive: /var/folders/9v/kys6gqns6kl8nksyn4l1f9v40000gn/T/.tmp3R7uhF/deno.zip inflating: deno Upgraded successfully ~/src/deno-docs/reference_gen# rm -rf /Users/ry/Library/Caches/deno ~/src/deno-docs/reference_gen# deno task types Task types deno task types:deno && deno task types:node Task types:deno deno run --allow-read --allow-write --allow-run --allow-env --allow-sys deno-docs.ts Task types:node deno run --allow-read --allow-write=. --allow-env --allow-sys node-docs.ts ```
2024-07-13refactor(fetch): reimplement fetch with hyper instead of reqwest (#24237)Sean McArthur
This commit re-implements `ext/fetch` and all dependent crates using `hyper` and `hyper-util`, instead of `reqwest`. The reasoning is that we want to have greater control and access to low level `hyper` APIs when implementing `fetch` API as well as `node:http` module. --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2024-07-02chore: upgrade to reqwest 0.12.4 and rustls 0.22 (#24388)Bartek Iwańczuk
Reland of https://github.com/denoland/deno/pull/24056 that doesn't suffer from the problem that was discovered in https://github.com/denoland/deno/pull/24261. It uses upgraded `hyper` and `hyper-util` that fixed the previous problem in https://github.com/hyperium/hyper/pull/3691.
2024-06-19Revert "chore: upgrade to reqwest 0.12.4 and rustls 0.22 (#24056)" (#24262)Bartek Iwańczuk
This reverts commit fb31eaa9ca59f6daaee0210d5cd206185c7041b9. Reverting because users reported spurious errors when downloading dependencies - https://github.com/denoland/deno/issues/24260. Closes https://github.com/denoland/deno/issues/24260
2024-06-13chore: upgrade to reqwest 0.12.4 and rustls 0.22 (#24056)Bartek Iwańczuk
This commit updates Deno to use `reqwest` at 0.12.4 and `rustls` at 0.22. Other related crates were updated as well to match versions accepted by `reqwest` and `rustls`. Note: we are not using the latest available `rustls` yet, but this upgrade was non-trivial already, so a bump to 0.23 for `rustls` will be done in a separate commit. Closes #23370 --------- Signed-off-by: Ryan Dahl <ry@tinyclouds.org> Signed-off-by: Bartek Iwańczuk <biwanczuk@gmail.com> Co-authored-by: Ryan Dahl <ry@tinyclouds.org> Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
2024-06-06refactor: remove `PermissionsContainer` in deno_runtime (#24119)David Sherret
Also removes permissions being passed in for node resolution. It was completely useless because we only checked it for reading package.json files, but Deno reading package.json files for resolution is perfectly fine. My guess is this is also a perf improvement because Deno is doing less work.
2024-05-09refactor(ext/tls): Implement required functionality for later SNI support ↵Matt Mastracci
(#23686) Precursor to #23236 This implements the SNI features, but uses private symbols to avoid exposing the functionality at this time. Note that to properly test this feature, we need to add a way for `connectTls` to specify a hostname. This is something that should be pushed into that API at a later time as well. ```ts Deno.test( { permissions: { net: true, read: true } }, async function listenResolver() { let sniRequests = []; const listener = Deno.listenTls({ hostname: "localhost", port: 0, [resolverSymbol]: (sni: string) => { sniRequests.push(sni); return { cert, key, }; }, }); { const conn = await Deno.connectTls({ hostname: "localhost", [serverNameSymbol]: "server-1", port: listener.addr.port, }); const [_handshake, serverConn] = await Promise.all([ conn.handshake(), listener.accept(), ]); conn.close(); serverConn.close(); } { const conn = await Deno.connectTls({ hostname: "localhost", [serverNameSymbol]: "server-2", port: listener.addr.port, }); const [_handshake, serverConn] = await Promise.all([ conn.handshake(), listener.accept(), ]); conn.close(); serverConn.close(); } assertEquals(sniRequests, ["server-1", "server-2"]); listener.close(); }, ); ``` --------- Signed-off-by: Matt Mastracci <matthew@mastracci.com>
2024-05-05fix(workers): `importScripts` concurrently and use a new `reqwest::Client` ↵David Sherret
per importScripts (#23699) 1. We were polling each future in sequence, so this meant it was fetching scripts in sequence. 2. It's not safe to share `reqwest::Client` across tokio runtimes (https://github.com/seanmonstar/reqwest/issues/1148#issuecomment-910868788)
2024-04-08refactor(ext/tls): use cppgc to deduplicate the tls key loading code (#23289)Matt Mastracci
Pass the certificates and key files as CPPGC objects. Towards #23233
2024-03-12refactor: add `deno_permissions` crate (#22236)Divy Srivastava
Issue https://github.com/denoland/deno/issues/22222 ![image](https://github.com/denoland/deno/assets/34997667/2af8474b-b919-4519-98ce-9d29bc7829f2) This PR moves `runtime/permissions` code to a upstream crate called `deno_permissions`. The `deno_permissions::PermissionsContainer` is put into the OpState and can be used instead of the current trait-based permissions system. For this PR, I've migrated `deno_fetch` to the new crate but kept the rest of the trait-based system as a wrapper of `deno_permissions` crate. Doing the migration all at once is error prone and hard to review. Comparing incremental compile times for `ext/fetch` on Mac M1: | profile | `cargo build --bin deno` | `cargo plonk build --bin deno` | | --------- | ------------- | ------------------- | | `debug` | 20 s | 0.8s | | `release` | 4 mins 12 s | 1.4s |
2024-02-18BREAKING: add `Deno.CreateHttpClientOptions.{cert,key}` (#22280)Asher Gomez
This change deprecates `Deno.CreateHttpClientOptions.{certChain,privateKey}` in favour of `Deno.CreateHttpClientOptions.{cert,key}`. Closes #22278 Co-authored-by: Matt Mastracci <matthew@mastracci.com>
2024-01-01chore: update copyright to 2024 (#21753)David Sherret
2023-12-31fix(http_client): Fix Deno.createHttpClient to accept poolIdleTimeout ↵Raashid Anwar
parameter (#21603) Fixed the bug `Deno.createHttpClient` to accept `poolIdleTimeout` parameter. Fixes https://github.com/denoland/deno/issues/21546
2023-12-27refactor: simplify hyper, http, h2 deps (#21715)Bartek Iwańczuk
Main change is that: - "hyper" has been renamed to "hyper_v014" to signal that it's legacy - "hyper1" has been renamed to "hyper" and should be the default
2023-12-23chore(ext/node): use BufView natively in http2 (#21688)Matt Mastracci
Node HTTP/2 was using the default h2 `Bytes` datatype when we can be making using of `BufView` like we do in `Deno.serve`. `fetch` and `Deno.serverHttp` can't make use of `BufView` because they are using `reqwest` which is stuck on hyper 0.x at this time.
2023-12-01refactor: use resourceForReadableStream for fetch (#20217)Matt Mastracci
Switch `ext/fetch` over to `resourceForReadableStream` to simplify and unify implementation with `ext/serve`. This allows us to work in Rust with resources only. Two additional changes made to `resourceForReadableStream` were required: - Add an optional length to `resourceForReadableStream` which translates to `size_hint` - Fix a bug where writing to a closed stream that was full would panic
2023-11-01feat(ext/websocket): websockets over http2 (#21040)Matt Mastracci
Implements `WebSocket` over http/2. This requires a conformant http/2 server supporting the extended connect protocol. Passes approximately 100 new WPT tests (mostly `?wpt_flags=h2` versions of existing websockets APIs). This is implemented as a fallback when http/1.1 fails, so a server that supports both h1 and h2 WebSockets will still end up on the http/1.1 upgrade path. The patch also cleas up the websockets handshake to split it up into http, https+http1 and https+http2, making it a little less intertwined. This uncovered a likely bug in the WPT test server: https://github.com/web-platform-tests/wpt/issues/42896
2023-10-31feat(ext/web): EventSource (#14730)Leo Kettmeir
Closes #10298 --------- Co-authored-by: Aapo Alasuutari <aapo.alasuutari@gmail.com>
2023-09-23refactor: rewrite ops using i64/usize to op2 (#20647)Bartek Iwańczuk
2023-09-21refactor: rewrite some ops to op2 macro (#20603)Bartek Iwańczuk
2023-08-23fix(ext/web): add stream tests to detect v8slice split bug (#20253)Matt Mastracci
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-08-09refactor(ext/fetch): Remove FetchRequestBodyResource from FetchHandler ↵Matt Mastracci
interface (#20100) This is unused and will allow us to remove `FetchRequestBodyResource` in a future PR.
2023-08-03refactor(ext/fetch): refactor fetch to use new write_error method (#20029)Matt Mastracci
This is a prerequisite for fast streams work -- this particular resource used a custom `mpsc`-style stream, and this work will allow us to unify it with the streams in `ext/http` in time. Instead of using Option as an internal semaphore for "correctly completed EOF", we allow code to propagate errors into the channel which can be picked up by downstream sinks like Hyper. EOF is signalled using a more standard sender drop.
2023-07-28feat: Deno.createHttpClient allowHost (#19689)Leo Kettmeir
This adds an option to allow using the host header in a fetch call. Closes https://github.com/denoland/deno/issues/16840 Ref https://github.com/denoland/deno/issues/11017
2023-06-22refactor(serde_v8): split ZeroCopyBuf into JsBuffer and ToJsBuffer (#19566)Bartek Iwańczuk
`ZeroCopyBuf` was convenient to use, but sometimes it did hide details that some copies were necessary in certain cases. Also it made it way to easy for the caller to pass around and convert into different values. This commit splits `ZeroCopyBuf` into `JsBuffer` (an array buffer coming from V8) and `ToJsBuffer` (a Rust buffer that will be converted into a V8 array buffer). As a result some magical conversions were removed (they were never used) limiting the API surface and preparing for changes in #19534.
2023-06-15refactor(ext/fetch): simplify fetch ops (#19494)Bartek Iwańczuk
Addresses feedback from https://github.com/denoland/deno/pull/19412#discussion_r1227912676
2023-06-13fix(ext/node): handle 'upgrade' responses (#19412)Bartek Iwańczuk
This commit adds support for "upgrade" events in "node:http" "ClientRequest". Currently only "Websocket" upgrades are handled. Thanks to this change package like "npm:puppeteer" and "npm:discord" should work. Closes https://github.com/denoland/deno/issues/18913 Closes https://github.com/denoland/deno/issues/17847
2023-05-29fix: use proper ALPN protocols if HTTP client is HTTP/1.1 only (#19303)Bartek Iwańczuk
Closes https://github.com/denoland/deno/issues/16923 --------- Co-authored-by: crowlkats <crowlkats@toaxl.com> Co-authored-by: Matt Mastracci <matthew@mastracci.com>
2023-05-21feat(unstable): add more options to Deno.createHttpClient (#17385)Leo Kettmeir
2023-05-17refactor(node): reimplement http client (#19122)Leo Kettmeir
This commit reimplements most of "node:http" client APIs using "ext/fetch". There is some duplicated code and two removed Node compat tests that will be fixed in follow up PRs. --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-05-01perf: lazily create RootCertStore (#18938)David Sherret
2023-03-23refactor: make version and user_agent &'static str (#18400)Bartek Iwańczuk
These caused a bunch of unnecessary allocations on each startup.
2023-03-17perf(core) Reduce copying and cloning in extension initialization (#18252)Matt Mastracci
Follow-up to #18210: * we are passing the generated `cfg` object into the state function rather than passing individual config fields * reduce cloning dramatically by making the state_fn `FnOnce` * `take` for `ExtensionBuilder` to avoid more unnecessary copies * renamed `config` to `options`
2023-03-17feat(core) deno_core::extension! macro to simplify extension registration ↵Matt Mastracci
(#18210) This implements two macros to simplify extension registration and centralize a lot of the boilerplate as a base for future improvements: * `deno_core::ops!` registers a block of `#[op]`s, optionally with type parameters, useful for places where we share lists of ops * `deno_core::extension!` is used to register an extension, and creates two methods that can be used at runtime/snapshot generation time: `init_ops` and `init_ops_and_esm`. --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-03-13feat(ext/fetch): support fallible request-builder hooks (#18116)Luca Bruno
This tweaks the signature of `request_builder_hook` in order to support fallible hooks. The rationale for this is mostly on two sides: * it allows a hook to inspect and possibly drop an outgoing request (e.g. for policying purposes), bubbling up a detailed error message to the user. * it wires into newer `reqwest` API which allows to split and then reassemble a `RequestBuilder`, although only in a fallible way (https://github.com/seanmonstar/reqwest/pull/1770)
2023-03-09refactor(core): remove RuntimeOptions::extensions_with_js (#18099)Bartek Iwańczuk
This commit removes "deno_core::RuntimeOptions::extensions_with_js". Now it's embedders' responsibility to properly register extensions that will not contains JavaScript sources when running from an existing snapshot. Prerequisite for https://github.com/denoland/deno/pull/18080
2023-03-09refactor: Split extension registration for runtime and snapshotting (#18095)Bartek Iwańczuk
This commit splits "<ext_name>::init" functions into "init_ops" and "init_ops_and_esm". That way we don't have to construct list of ESM sources on each startup if we're running with a snapshot. In a follow up commit "deno_core" will be changed to not have a split between "extensions" and "extensions_with_js" - it will be embedders' responsibility to pass appropriately configured extensions. Prerequisite for https://github.com/denoland/deno/pull/18080
2023-03-09refactor(core): Extension::builder_with_deps (#18093)Bartek Iwańczuk
Prerequisite for https://github.com/denoland/deno/pull/18080