261 Commits

Author SHA1 Message Date
Sean McArthur
4492f31e94 fix(http1): fix consuming extra CPU from previous change (#3977)
Revert "fix(http1): fix rare missed write wakeup on connections (#3952)"

This reverts commit 2377b893f6.
2025-11-13 16:11:36 -05:00
Sean McArthur
0a37a8cd9d test(ready_stream): replace tracing with printlns (#3973) 2025-11-10 10:09:27 -05:00
Louis Thiery
2377b893f6 fix(http1): fix rare missed write wakeup on connections (#3952) 2025-11-10 09:51:16 -05:00
katelyn martin
f9f8f44058 tests(client): port tests to in-memory socket (#3947)
see https://github.com/hyperium/hyper/issues/3896.

this commit ports an assortment of test cases for the client to an
in-memory socket using `tokio::io::duplex()`.

this should help reduce test flakes related to TCP close behavior.

this supersedes https://github.com/hyperium/hyper/pull/3946.

Signed-off-by: katelyn martin <git@katelyn.world>
2025-09-08 12:39:18 -04:00
Finn Bear
10b09ffc04 fix(server): start http1 header read timeout when conn is idle (#3828)
Currently, the header read timeout is started before any part of the first request is received. This allows closing the connection if no requests are received. However, after the first request, the connection can remain open indefinitely. This change ensures that the header read timeout is started immediately after the connection is idle, following the transmission of the response, before the first part of the subsequent request is received.

This change allows a potential future addition of an idle_timeout, which if set, would be used instead of the header_read_timeout. This behavior is matched in other servers, such as Golang.

Fixes #3780
Closes #3781
2025-01-27 15:23:46 -05:00
Sean McArthur
8ce1fcfae9 feat(ext): add ext::on_informational() callback extension (#3818)
This new function allows attaching a callback to a request, such that
when it is sent through a hyper client connection, and any 1xx
informational responses are received, they are passed to the callback.

This takes the unstable client informational feature (introduced in
#2594, tracking issue in #2565), and promotes it to a stable API.

Closes #2565
2025-01-27 14:15:58 -05:00
Sean McArthur
a131111f9c fix(http1): fix intermitent panic parsing partial headers (#3812)
Closes #3811
2024-12-16 10:36:41 -05:00
Lin Yihai
0bd4adfed2 refactor(lib): reduce clippy warnings (#3805) 2024-12-06 11:04:54 -05:00
Sean McArthur
17fddd3317 test(client): unflake client try_send_request unit test 2024-10-22 13:54:52 -07:00
Sean McArthur
c86a6bcb4a fix(http1): send 'connection: close' when connection is ending (#3725)
This includes conditions where hyper knows the connection will end after the response, such as a request error that ruins the connection, or when graceful shutdown is triggered.

Closes #3720
2024-10-11 14:28:29 -04:00
Sean McArthur
8e5de1bb57 fix(http1): reject final chunked if missing 0
If a chunked body had valid chunks, but ended without a `0` in the final
chunk (so, just `\r\n\r\n`), it would be parsed as a valid end. Now it
will be rejected as the final chunk MUST be `0\r\n\r\n`.

This was partially done before, but only if there were no chunks before
the final. This fixes both paths.
2024-07-09 06:05:02 -07:00
Sean McArthur
4ffaad53c7 feat(client): add SendRequest::try_send_request() method (#3691)
This method returns a `TrySendError` type, which allows for returning
the request back to the caller if an error occured between queuing and
trying to write the request.

This method is added for both `http1` and `http2`.
2024-07-01 09:19:43 -04:00
Sean McArthur
0eb1b6cf4d fix(server): start header read timeout immediately (#3185)
The `http1_header_read_timeout` used to start once there was a single
read of headers. This change makes it start the timer immediately, right
when the connection is estabilished.
2024-06-03 15:18:14 -04:00
John Howard
a8f9e06ae5 Add test for HTTP2 CONNECT termination (#3655) 2024-05-17 08:46:46 -04:00
Herman J. Radtke III
ac84af6b32 feat(http1): add support for receiving trailer fields (#3637)
This allows receiving HTTP/1 chunked trailers, both as a client
and as a server.

The number of trailer pairs is limited to 1024.

The size of the trailer fields is limited. The limit accounts for a
single, very large trailer field or many trailer fields that exceed the
limit in aggregate.

Closes #2703
2024-05-13 15:24:25 -04:00
Edward C
721785efad feat(server): add Builder::auto_date_header(bool) to allow disabling Date headers
The default is enabled `true`. The method exists on both HTTP/1 and HTTP/2 builders.
2024-04-29 14:12:22 -04:00
Sean McArthur
3705a7e430 Revert "fix(client): send content-length even with no body"
This reverts commit 172fdfaf0e.
2024-04-16 08:36:54 -04:00
Sean McArthur
172fdfaf0e fix(client): send content-length even with no body
Most request methods define a payload. If hyper detects that no body has
been included, it will now include a `content-length: 0` header
automatically.

It will not do this for methods that don't have defined payloads (GET,
HEAD, and CONNECT).
2024-04-15 07:26:12 -04:00
Artem Medvedev
6ecf85218f fix: avoid graceful_shutdown panic on upgraded H1 connection (#3616) 2024-03-31 23:30:30 +08:00
tottoto
90eb95f62a chore(lib): remove importing prelude trait in 2021 edition (#3546) 2024-01-28 08:02:12 -05:00
Herman J. Radtke III
31b4180752 feat(http1): Add support for sending HTTP/1.1 Chunked Trailer Fields (#3375)
Closes #2719
2023-12-15 13:37:48 -05:00
Sean McArthur
899e92a580 feat(lib): update to http 1.0
Updates dependencies `http` and `http-body` to 1.0.

To do so, implements `Clone` for `OnUpgrade`.

BREAKING CHANGE: Upgrade to `http` 1.0.
2023-11-15 12:22:48 -05:00
Sean McArthur
569a42d5c9 test(support): fix up unused lint (#3374) 2023-10-26 08:26:41 -04:00
tottoto
2018545bf8 chore(tests): Replace matches crate with std assert and matches macro (#3315) 2023-09-17 07:13:55 -04:00
Sean McArthur
50f123afc0 feat(error): change Display for Error to only print top error (#3312)
hyper's `Error` used to print the error source automatically, preferring
to provide a better default for users who do not know about `Report`.
But, to fit better with the wider ecosystem, this changes the format to
only print the hyper `Error` itself, and not its source.

Closes #2844

BREAKING CHANGE: The format no longer prints the error chain. Be sure to
  check if you are logging errors directly.

  The `Error::message()` method is removed, it is no longer needed.

  The `Error::into_cause()` method is removed.
2023-09-13 09:10:36 -04:00
Max
43d2f5c6cf fix(server): Respect Expect header only when http proto > 1.0 (#3294) 2023-08-23 11:48:52 -04:00
Artem Medvedev
194e6f9847 fix(client): early server response shouldn't propagate NO_ERROR (#3275)
Closes #2872
2023-07-26 15:47:06 -04:00
Sean McArthur
f9f65b7aa6 feat(rt): replace IO traits with hyper::rt ones (#3230)
This replaces the usage of `tokio::io::{AsyncRead, AsyncWrite}` in hyper's public API with new traits in the `hyper::rt` module.

Closes #3110

BREAKING CHANGE: 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.
2023-07-10 14:11:06 -04:00
Sean McArthur
f4b513009d fix(http1): http1 server graceful shutdown fix (#3261)
fix issue in the graceful shutdown logic
which causes the connection future to hang
when graceful shutdown is called prior to any
requests being  made. This fix checks to see
if the connection is still in its initial state
when disable_keep_alive is called, and starts the
shutdown process if it is.

This addresses issue #2730

Co-authored-by: Robin Seitz <roseitz@microsoft.com>
2023-07-06 15:23:29 -04:00
Sean McArthur
fec64cf0ab fix(http1): properly end chunked bodies when it was known to be empty (#3254)
Closes #3252
2023-06-19 11:16:43 -04:00
tottoto
8552543fd2 chore(dependencies): use futures-core via futures-util consistently (#3219) 2023-05-17 17:04:25 -04:00
rob2244
d894439e00 feat(service): change Service::call to take &self (#3223)
change Service::call to take &self instead of &mut self.
Because of this change, the trait bound in the service::util::service_fn and
the trait bound in the impl for the ServiceFn struct were changed from FnMut to Fn.
This change was decided on for the following reasons:
- It prepares the way for async fn,
  since then the future only borrows &self, and thus a Service can concurrently handle
  multiple outstanding requests at once.
- It's clearer that Services can likely be cloned
- To share state across clones you generally need Arc<Mutex<_>>
  that means you're not really using the &mut self and could do with a &self

Closes #3040

BREAKING CHANGE: 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-05-15 15:20:34 -04:00
Sean McArthur
499fe1f949 fix(server): prevent sending 100-continue if user drops request body (#3137) 2023-02-02 09:12:57 -05:00
dswij
8068aa011f feat(client): http2 builder now requires an Executor (#3135)
This commit removes `common::Exec::Default` that just panics when used. We are
removing `tokio`, leaving `Exec::Default` with no implementation and
panics when `Exec::execute` is called.

Since `Exec::Default` has no purpose, it is being removed and user
should now provide an implementation of executor.

Closes #3128 

BREAKING CHANGE:  `hyper::client::conn::Http2::Builder::new` now requires an executor argument.
2023-01-31 15:18:30 -05:00
Andy Caldwell
1de9accf1e feat(client): remove unneeded HTTP/1 executor (#3108)
BREAKING CHANGE: The method
  `hyper::client::conn::http1::Builder::executor()` is removed, since it did nothing.
2023-01-04 18:35:09 -05:00
Michael-J-Ward
291ed0b49b feat(server): remove http1_ method prefixes from server::conn::http2::Builder
Refs: #3085
2022-12-28 11:29:58 -05:00
Michael-J-Ward
48e70c691e feat(server): remove http1_ method prefixes from server::conn::http2::Builder
Refs: #3085
2022-12-28 11:29:58 -05:00
Michael-J-Ward
669df2173e feat(client): remove http2_ prefixes from client::conn::http2::Builder methods
Refs: #3085
2022-12-28 11:29:58 -05:00
Michael-J-Ward
4cbaef79f0 feat(client): remove http1_ prefixes from client::conn::http1::Builder methods
Refs: #3085
2022-12-28 11:29:58 -05:00
Alexander
54eaf7fb13 refactor(test): use setup fns for logger/listeners (#3081)
This is a continuation of work on #1675 issue. It slightly
reduces the number of duplicated code by using one common function for
init a logger and creating tcp listener for tests.
2022-12-12 14:49:39 -05:00
Alexander
fdffc1d52f refactor(test): use fns for creating test server (#3072)
This is a part of #1675 issue. It slightly reduces the number of
duplicated code by using one common function for init a logger and
creating a Tokio server.
2022-12-05 16:16:54 -05:00
Anthony Ramine
75aac9f47f fix(client): send an error back to client when dispatch misbehaves (fixes #2649) 2022-10-31 09:37:18 -04:00
Sean McArthur
95a153bbc2 feat(body): rename Recv to Incoming (#3022)
The concrete "recv stream" body type is renamed to `Incoming`.

Closes #2971
2022-10-25 16:27:17 -04:00
Sean McArthur
0888623d37 feat(body): update Body trait to use Frames (#3020)
The `Body` trait was adjusted to be forwards compatible with adding new
frame types. That resulted in changing from `poll_data` and `poll_trailers`
to a single `poll_frame` function. More can be learned from the proposal
in https://github.com/hyperium/hyper/issues/2840.

Closes #3010

BREAKING CHANGE: The polling functions of the `Body` trait have been
  redesigned.

  The free functions `hyper::body::to_bytes` and `aggregate` have been
  removed. Similar functionality is on
  `http_body_util::BodyExt::collect`.
2022-10-24 18:07:45 -04:00
Sean McArthur
0766d3f78d feat(server): remove server::conn::{Http, Connection} types (#3013)
The connection types have been split into version-specific types, in the
`server::conn::{http1, http2}` modules.

Closes #3012

BREAKING CHANGE: Either choose a version-specific `Connection` type, or
  look for the auto-version type in `hyper-util`.
2022-10-17 13:23:47 -04:00
Sean McArthur
8ae73cac6a feat(client): remove client::conn::{SendRequest, Connection} (#2987)
BREAKING CHANGE: Pick a version-specific connection, or use the combined
  one in `hyper-util`.

Co-authored-by: mkusaka <hinoshita1992@gmail.com>
2022-09-21 09:20:07 -07:00
Oddbjørn Grødem
23a56005bd feat(client, server): remove runtime cargo feature (#2975)
- There is no longer a `runtime` feature to enable in the `Cargo.toml.`
- Forgetting to set an executor will now panic.

Closes #2857

BREAKING CHANGE: No longer need to enable a `runtime` feature. All connection builders should set an executor.
2022-09-15 11:23:45 -07:00
Tom Karwowski
fee7d361c2 feat(service): create own Service trait (#2920)
This removes the dependency on `tower-service`, and simplifies the `Service` trait to be used by hyper's server connections.

Closes #2853 

BREAKING CHANGE: Change any manual `impl tower::Service` to implement `hyper::service::Service` instead. The `poll_ready` method has been removed.
2022-09-08 15:25:20 -07:00
Sean McArthur
fae97ced3a feat(rt): add Timer trait (#2974)
This adds a `hyper::rt::Timer` trait, and it is used in connection
builders to configure a custom timer source for timeouts.

Co-authored-by: Robert Cunningham <robertvcunningham@gmail.com>
2022-09-02 13:26:55 -07:00
Rajiv Sharma
031454e5e6 fest(body): rename HttpBody export to Body (#2969)
Now that the concrete `Body` type has been temporarily replaced with `Recv` in #2966,
we can rename and export `http_body::Body` as just `Body` instead of `HttpBody`.

Closes #2839

BREAKING CHANGE: The trait has been renamed.
2022-08-30 05:55:06 -07:00