summaryrefslogtreecommitdiff
path: root/ext/http/http_next.rs
AgeCommit message (Collapse)Author
2024-11-18feat(ext/http): Make http server parameters configurable (#26785)Yusuke Tanaka
This commit makes http server parameters configurable on the extension initialization via two callbacks users can provide. The main motivation behind this change is to allow `deno_http` users to tune the HTTP/2 server 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 hook functions. If not provided, the default configuration from hyper crate will be used.
2024-11-12fix(ext/http): prefer brotli for `accept-encoding: gzip, deflate, br, zstd` ↵Satya Rohith
(#26814) Closes https://github.com/denoland/deno/issues/26813
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-10-18refactor(ext/http): use concrete error types (#26377)Leo Kettmeir
2024-10-18refactor(ext/websocket): use concrete error type (#26226)Leo Kettmeir
2024-10-16perf(http): make heap allocation for path conditional (#26289)David Sherret
Code: ```js Deno.serve({ port: 8085 }, request => { return new Response(request.url); }); ``` Before: ``` % wrk -d60s http://localhost:8085/path/testing\?testing=5 Running 1m test @ http://localhost:8085/path/testing?testing=5 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 56.01us 18.34us 3.28ms 93.84% Req/Sec 81.80k 3.13k 88.26k 90.77% 9783713 requests in 1.00m, 1.67GB read Requests/sec: 162789.89 Transfer/sec: 28.41MB ``` After: ``` % wrk -d60s http://localhost:8085/path/testing\?testing=5 Running 1m test @ http://localhost:8085/path/testing?testing=5 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 55.44us 15.20us 2.42ms 90.41% Req/Sec 82.71k 2.92k 88.10k 89.93% 9892916 requests in 1.00m, 1.69GB read Requests/sec: 164607.06 Transfer/sec: 28.73MB ```
2024-10-14perf(http): avoid clone getting request method and url (#26250)David Sherret
2024-09-12feat: stabilize `Deno.createHttpClient()` (#25569)Asher Gomez
Closes #25518
2024-08-21feat: Upgrade V8 to 12.9 (#25138)Bartek Iwańczuk
2024-04-24feat(ext/http): Implement request.signal for Deno.serve (#23425)Matt Mastracci
When the response has been successfully send, we abort the `Request.signal` property to indicate that all resources associated with this transaction may be torn down.
2024-04-10chore: update to Rust 1.77.2 (#23262)林炳权
update to Rust 1.77.2 --------- Co-authored-by: Matt Mastracci <matthew@mastracci.com>
2024-03-04chore: fix typos (#22677)cui fliter
2024-01-26fix(ext/http): smarter handling of Accept-Encoding (#22130)Matt Mastracci
2024-01-09chore: upgrade deno_core to 0.244.0 (#21859)Bartek Iwańczuk
2024-01-01chore: update copyright to 2024 (#21753)David Sherret
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-22chore: update ext/http to hyper 1.0.1 and http 1.0 (#21588)Bartek Iwańczuk
Closes https://github.com/denoland/deno/issues/21583.
2023-12-14refactor(ext/http): fork fly_accept_encodings crate (#21586)Bartek Iwańczuk
Blocks update to Hyper 1.0. It's a really small library, no need to pull it as a dependency. Blocker for #21583
2023-12-06feat: stabilize Deno.HttpServer.shutdown and Unix socket support (#21463)Bartek Iwańczuk
This commit stabilizes "Deno.HttpServer.shutdown" API as well as Unix socket support in "Deno.serve" API. --------- Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
2023-11-23fix(ext/http): avoid lockup in graceful shutdown (#21253)Matt Mastracci
Follow-up to #20822. cc @lrowe The `httpServerExplicitResourceManagement` tests were randomly failing on CI because of a race. The `drain` waker was missing wakeup events if the listeners shut down after the last HTTP response finished. If we lost the race (rare), the server Rc would be dropped and we wouldn't poll it again. This replaces the drain waker system with a signalling Rc that always resolves when the refcount is about to become 1. Fix verified by running serve tests in a loop: ``` for i in {0..100}; do cargo run --features=__http_tracing -- test -A --unstable '/Users/matt/Documents/github/deno/deno/cli/tests/unit/ser ve_test.ts' --filter httpServerExplicitResourceManagement; done; ```
2023-11-18fix(ext/http): fix crash in dropped Deno.serve requests (#21252)Matt Mastracci
Fixes #21250 We were attempting to recycle dropped resource responses too early.
2023-11-15feat(ext/net): use rustls_tokio_stream (#21205)Matt Mastracci
Fixes #21121 and #19498 Migrates fully to rustls_tokio_stream. We no longer need to maintain our own TlsStream implementation to properly support duplex. This should fix a number of errors with TLS and websockets, HTTP and "other" places where it's failing.
2023-11-13refactor(ext/http): Use HttpRecord as response body to track until body ↵Laurence Rowe
completion (#20822) Use HttpRecord as response body so requests can be tracked all the way to response body completion. This allows Request properties to be accessed while the response body is streaming. Graceful shutdown now awaits a future instead of async spinning waiting for requests to finish. On the minimal benchmark this refactor improves performance an additional 2% over pooling alone for a net 3% increase over the previous deno main branch. Builds upon https://github.com/denoland/deno/pull/20809 and https://github.com/denoland/deno/pull/20770. --------- Co-authored-by: Matt Mastracci <matthew@mastracci.com>
2023-11-13perf(ext/http): Object pooling for HttpRecord and HeaderMap (#20809)Laurence Rowe
Reuse existing existing allocations for HttpRecord and response HeaderMap where possible. At request end used allocations are returned to the pool and the pool and the pool sized to 1/8th the current number of inflight requests. For http1 hyper will reuse the response HeaderMap for the following request on the connection. Builds upon https://github.com/denoland/deno/pull/20770 --------- Co-authored-by: Matt Mastracci <matthew@mastracci.com>
2023-11-13refactor(ext/http): refer to HttpRecord directly using v8::External (#20770)Laurence Rowe
Makes the JavaScript Request use a v8:External opaque pointer to directly refer to the Rust HttpRecord. The HttpRecord is now reference counted. To avoid leaks the strong count is checked at request completion. Performance seems unchanged on the minimal benchmark. 118614 req/s this branch vs 118564 req/s on main, but variance between runs on my laptop is pretty high. --------- Co-authored-by: Matt Mastracci <matthew@mastracci.com>
2023-10-25chore: update deno_core and port all remaining ops to `op2` (#20954)Bartek Iwańczuk
Signed-off-by: Matt Mastracci <matthew@mastracci.com> Co-authored-by: Matt Mastracci <matthew@mastracci.com>
2023-10-12refactor: FeatureChecker integration in ext/ crates (#20797)Bartek Iwańczuk
Towards https://github.com/denoland/deno/issues/20779.
2023-10-04refactor: use deno_core::FeatureChecker for unstable checks (#20765)Bartek Iwańczuk
2023-09-26refactor(ext/http): use scopeguard defer to handle async drop (#20652)Laurence Rowe
Use the [scopeguard](https://docs.rs/scopeguard/) defer macro to run cleanup code for `new_slab_future`. This means it can be a single async function, avoiding the need to create a struct and implement `PinnedDrop` Async cleanup in Rust is awkward because async functions may be cancelled at any await point when their Future is dropped. The scopeguard approach comes from the following articles: * [How to think about `async`/`await` in Rust](http://cliffle.com/blog/async-inversion/) * [Async Cancellation I](https://blog.yoshuawuyts.com/async-cancellation-1/) (Reddit [discussion](https://www.reddit.com/r/rust/comments/qrhg39/blog_post_async_cancellation/))
2023-09-25fix(ext/http): ensure that resources are closed when request is cancelled ↵Matt Mastracci
(#20641) Builds on top of #20622 to fix #10854
2023-09-24refactor: rewrite more ops to op2 (#20666)Bartek Iwańczuk
2023-09-23refactor: rewrite ops to op2 macro (#20628)Bartek Iwańczuk
Co-authored-by: Matt Mastracci <matthew@mastracci.com>
2023-09-16perf(ext/http): optimize `set_response` for small responses (#20527)Marcos Casagrande
This PR introduces an optimization to `set_response` to reduce the overhead for responses with a payload size less than 64 bytes. Performance gains are more noticeable when `is_request_compressible` enters the slow path, ie: `-H 'Accept-Encoding: unknown'` ### Benchmarks ```js Deno.serve({ port: 3000 }, () => new Response("hello")); ``` ``` wrk -d 10s --latency -H 'Accept-Encoding: slow' http://127.0.0.1:3000 ``` --- **main** ``` Running 10s test @ http://127.0.0.1:3000 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 44.72us 28.12us 3.10ms 97.95% Req/Sec 112.73k 8.25k 123.66k 91.09% 2264092 requests in 10.10s, 308.77MB read Requests/sec: 224187.08 Transfer/sec: 30.57MB ``` **this PR** ``` Running 10s test @ http://127.0.0.1:3000 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 42.91us 20.57us 2.04ms 97.36% Req/Sec 116.61k 7.95k 204.81k 88.56% 2330970 requests in 10.10s, 317.89MB read Requests/sec: 230806.32 Transfer/sec: 31.48MB ```
2023-09-12fix(ext/http): create a graceful shutdown API (#20387)Matt Mastracci
This PR implements a graceful shutdown API for Deno.serve, allowing all current connections to drain from the server before shutting down, while preventing new connections from being started or new transactions on existing connections from being created. We split the cancellation handle into two parts: a listener handle, and a connection handle. A graceful shutdown cancels the listener only, while allowing the connections to drain. The connection handle aborts all futures. If the listener handle is cancelled, we put the connections into graceful shutdown mode, which disables keep-alive on http/1.1 and uses http/2 mechanisms for http/2 connections. In addition, we now guarantee that all connections are complete or cancelled, and all resources are cleaned up when the server `finished` promise resolves -- we use a Rust-side server refcount for this. Performance impact: does not appear to affect basic serving performance by more than 1% (~126k -> ~125k) --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-08-28fix(ext/http): don't panic on stream responses in cancelled requests (#20316)Matt Mastracci
When a TCP connection is force-closed (ie: browser refresh), the underlying future we pass to Hyper is dropped which may cause us to try to drop the body resource while the OpState lock is still held. Preconditions for this bug to trigger: - The body resource must have been taken - The response must return a resource (which requires us to take the OpState lock) - The TCP connection must have been dropped before this Fixes #20315 and #20298
2023-08-26chore: update to Rust 1.72 (#20258)林炳权
<!-- Before submitting a PR, please read https://deno.com/manual/contributing 1. Give the PR a descriptive title. Examples of good title: - fix(std/http): Fix race condition in server - docs(console): Update docstrings - feat(doc): Handle nested reexports Examples of bad title: - fix #7123 - update docs - fix bugs 2. Ensure there is a related issue and it is referenced in the PR text. 3. Ensure there are tests that cover the changes. 4. Ensure `cargo test` passes. 5. Ensure `./tools/format.js` passes without changing files. 6. Ensure `./tools/lint.js` passes. 7. Open as a draft PR if your work is still in progress. The CI won't run all steps, but you can add '[ci]' to a commit message to force it to. 8. If you would like to run the benchmarks on the CI, add the 'ci-bench' label. --> As the title. --------- Co-authored-by: Matt Mastracci <matthew@mastracci.com>
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-21fix(ext/http): ensure request body resource lives as long as response is ↵Matt Mastracci
alive (#20206) Deno.serve's fast streaming implementation was not keeping the request body resource ID alive. We were taking the `Rc<Resource>` from the resource table during the response, so a hairpin duplex response that fed back the request body would work. However, if any JS code attempted to read from the request body (which requires the resource ID to be valid), the response would fail with a difficult-to-diagnose "EOF" error. This was affecting more complex duplex uses of `Deno.fetch` (though as far as I can tell was unreported). Simple test: ```ts const reader = request.body.getReader(); return new Response( new ReadableStream({ async pull(controller) { const { done, value } = await reader.read(); if (done) { controller.close(); } else { controller.enqueue(value); } }, }), ``` And then attempt to use the stream in duplex mode: ```ts async function testDuplex( reader: ReadableStreamDefaultReader<Uint8Array>, writable: WritableStreamDefaultWriter<Uint8Array>, ) { await writable.write(new Uint8Array([1])); const chunk1 = await reader.read(); assert(!chunk1.done); assertEquals(chunk1.value, new Uint8Array([1])); await writable.write(new Uint8Array([2])); const chunk2 = await reader.read(); assert(!chunk2.done); assertEquals(chunk2.value, new Uint8Array([2])); await writable.close(); const chunk3 = await reader.read(); assert(chunk3.done); } ``` In older versions of Deno, this would just lock up. I believe after 23ff0e722e3c4b0827940853c53c5ee2ede5ec9f, it started throwing a more explicit error: ``` httpServerStreamDuplexJavascript => ./cli/tests/unit/serve_test.ts:1339:6 error: TypeError: request or response body error: error reading a body from connection: Connection reset by peer (os error 54) at async Object.pull (ext:deno_web/06_streams.js:810:27) ```
2023-08-17feat(ext/web): resourceForReadableStream (#20180)Matt Mastracci
Extracted from fast streams work. This is a resource wrapper for `ReadableStream`, allowing us to treat all `ReadableStream` instances as resources, and remove special paths in both `fetch` and `serve`. Performance with a ReadableStream response yields ~18% improvement: ``` return new Response(new ReadableStream({ start(controller) { controller.enqueue(new Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100])); controller.close(); } }) ``` This patch: ``` 12:36 $ third_party/prebuilt/mac/wrk http://localhost:8080 Running 10s test @ http://localhost:8080 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 99.96us 100.03us 6.65ms 98.84% Req/Sec 47.73k 2.43k 51.02k 89.11% 959308 requests in 10.10s, 117.10MB read Requests/sec: 94978.71 Transfer/sec: 11.59MB ``` main: ``` Running 10s test @ http://localhost:8080 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 163.03us 685.51us 19.73ms 99.27% Req/Sec 39.50k 3.98k 66.11k 95.52% 789582 requests in 10.10s, 82.83MB read Requests/sec: 78182.65 Transfer/sec: 8.20MB ```
2023-08-10perf(http): use Cow<[u8]> for setting header (#20112)Bartek Iwańczuk
2023-08-03refactor: rewrite http_next ops to use op2 macro (#19934)Bartek Iwańczuk
Ref #19915 --------- Co-authored-by: Matt Mastracci <matthew@mastracci.com>
2023-07-31feat(ext/http): Upgrade to hyper1.0-rc4 (#19987)Matt Mastracci
Includes a lightly-modified version of hyper-util's `TokioIo` utility. Hyper changes: v1.0.0-rc.4 (2023-07-10) Bug Fixes http1: http1 server graceful shutdown fix (#3261) ([f4b51300](https://github.com/hyperium/hyper/commit/f4b513009d81083081d1c60c1981847bbb17dd5d)) send error on Incoming body when connection errors (#3256) ([52f19259](https://github.com/hyperium/hyper/commit/52f192593fb9ebcf6d3894e0c85cbf710da4decd), closes https://github.com/hyperium/hyper/issues/3253) properly end chunked bodies when it was known to be empty (#3254) ([fec64cf0](https://github.com/hyperium/hyper/commit/fec64cf0abdc678e30ca5f1b310c5118b2e01999), closes https://github.com/hyperium/hyper/issues/3252) Features client: Make clients able to use non-Send executor (#3184) ([d977f209](https://github.com/hyperium/hyper/commit/d977f209bc6068d8f878b22803fc42d90c887fcc), closes https://github.com/hyperium/hyper/issues/3017) rt: replace IO traits with hyper::rt ones (#3230) ([f9f65b7a](https://github.com/hyperium/hyper/commit/f9f65b7aa67fa3ec0267fe015945973726285bc2), closes https://github.com/hyperium/hyper/issues/3110) add downcast on Sleep trait (#3125) ([d92d3917](https://github.com/hyperium/hyper/commit/d92d3917d950e4c61c37c2170f3ce273d2a0f7d1), closes https://github.com/hyperium/hyper/issues/3027) service: change Service::call to take &self (#3223) ([d894439e](https://github.com/hyperium/hyper/commit/d894439e009aa75103f6382a7ba98fb17da72f02), closes https://github.com/hyperium/hyper/issues/3040) Breaking Changes Any IO transport type provided must not implement hyper::rt::{Read, Write} instead of tokio::io traits. You can grab a helper type from hyper-util to wrap Tokio types, or implement the traits yourself, if it's a custom type. ([f9f65b7a](https://github.com/hyperium/hyper/commit/f9f65b7aa67fa3ec0267fe015945973726285bc2)) client::conn::http2 types now use another generic for an Executor. Code that names Connection needs to include the additional generic parameter. ([d977f209](https://github.com/hyperium/hyper/commit/d977f209bc6068d8f878b22803fc42d90c887fcc)) The Service::call function no longer takes a mutable reference to self. The FnMut trait bound on the service::util::service_fn function and the trait bound on the impl for the ServiceFn struct were changed from FnMut to Fn.
2023-07-25fix(ext/http): Quietly ignore invalid status codes (#19936)Matt Mastracci
2023-07-20refactor(ext/http): Use const thread-local initializer for slightly better ↵Matt Mastracci
perf (#19881) Benchmarking shows numbers are pretty close, however this is recommended for the best possible thread-local performance and may improve in future Rust compiler revisions.
2023-07-18fix(ext/node): check if resource can be used with write_vectored (#19868)Divy Srivastava
Fixes https://github.com/denoland/deno/issues/19766 Fixes https://github.com/denoland/deno/issues/19846
2023-07-07perf(ext/node): native vectored write for server streams (#19752)Divy Srivastava
``` # main $ ./load_test 10 0.0.0.0 8080 0 0 Using message size of 20 bytes Running benchmark now... Msg/sec: 106182.250000 Msg/sec: 110279.750000 ^C # this PR $ ./load_test 10 0.0.0.0 8080 0 0 Using message size of 20 bytes Running benchmark now... Msg/sec: 131632.250000 Msg/sec: 134754.250000 ^C ```
2023-06-26chore: fix typos (#19572)Martin Fischer
2023-06-24refactor(ops): Adding op2 macro and implementing in a couple of places (#19534)Matt Mastracci
This is a new op system that will eventually replace `#[op]`. Features - More maintainable, generally less-coupled code - More modern Rust proc-macro libraries - Enforces correct `fast` labelling for fast ops, allowing for visual scanning of fast ops - Explicit marking of `#[string]`, `#[serde]` and `#[smi]` parameters. This first version of op2 supports integer and Option<integer> parameters only, and allows us to start working on converting ops and adding features.
2023-06-13chore(ext/http): fix github lint issue (#19479)Matt Mastracci