158 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
tottoto
8552543fd2 chore(dependencies): use futures-core via futures-util consistently (#3219) 2023-05-17 17:04:25 -04: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
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
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
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
Oddbjørn Grødem
d963e6a950 feat(body): make body::Sender and Body::channel private (#2970)
Closes #2962 

BREAKING CHANGE: A channel body will be available in `hyper-util`.
2022-08-29 13:30:42 -07:00
Michael J Ward
7a41da5f60 refactor(body): rename Body to Recv temporarily (#2966)
"""
We'll eventually want to bikshed the name Recv, but to free up the name Body for #2839, this can be done quickly.
"""

Closes #2963
2022-08-26 08:47:14 -07:00
Sean McArthur
9e8fc8fca1 feat(body): remove "full" constructors from Body (#2958)
The constructors of `hyper::Body` from a full bytes are removed. Along
with `Body::empty()`.

BREAKING CHANGE: Use the types from `http-body-util`.

Co-authored-by: Xuanwo <github@xuanwo.io>
2022-08-24 13:01:26 -07:00
Sean McArthur
bb3af17ce1 feat(client): remove higher-level hyper::Client (#2941)
This removes the following types and methods from hyper:

- `Client`
- `Error::is_connect()`

BREAKING CHANGE: A pooling client is in the hyper-util crate.
2022-08-15 09:15:59 -07:00
Sean McArthur
0c8ee93d7f feat(client,server): remove tcp feature and code (#2929)
This removes the `tcp` feature from hyper's `Cargo.toml`, and the code it enabled:

- `HttpConnector`
- `GaiResolver`
- `AddrStream`

And parts of `Client` and `Server` that used those types. Alternatives will be available in the `hyper-util` crate.

Closes #2856 
Co-authored-by: MrGunflame <mrgunflame@protonmail.com>
2022-07-29 10:07:09 -07:00
Sean McArthur
d4b5bd4ee6 fix(http1): trim obs-folded headers when unfolding (#2926) 2022-07-27 07:00:53 -07:00
Sean McArthur
3660443108 test(client,server): add back tests around streaming bodies (#2905) 2022-06-29 06:39:21 -07:00
Oddbjørn Grødem
ce72f73464 feat(lib): remove stream cargo feature (#2896)
Closes #2855
2022-06-23 15:12:24 -07:00
Adam C. Foltzer
b2052a433f feat(ext): support non-canonical HTTP/1 reason phrases (#2792)
Add a new extension type `hyper::ext::ReasonPhrase` gated by either the `ffi` or `http1` Cargo
features. When enabled, store any non-canonical reason phrases in this extension when parsing
responses, and write this reason phrase instead of the canonical reason phrase when emitting
responses.

Reason phrases are a disused corner of the spec that implementations ought to treat as opaque blobs
of bytes. Unfortunately, real-world traffic sometimes does depend on being able to inspect and
manipulate them.

Non-canonical reason phrases are checked for validity at runtime to prevent invalid and dangerous
characters from being emitted when writing responses. An `unsafe` escape hatch is present for hyper
itself to create reason phrases that have been parsed (and therefore implicitly validated) by
httparse.
2022-06-08 15:57:33 -07:00
Anthony Ramine
1f0c177b35 feat(http1): implement obsolete line folding (#2734)
The client now has an option to allow parsing responses with obsolete line folding in headers. The option is off by default, since the spec recommends to reject such things if you can.
2022-02-09 12:59:23 -08:00
Sean McArthur
1010614a0d test(client): refactor client helper macro to handle options better 2021-11-24 14:26:26 -08:00
Sean McArthur
9d253d3168 test(client): fix extra semi-colon warning in helper macro 2021-08-04 11:45:03 -07:00
Anthony Ramine
5442b6fadd feat(http2): Implement Client-side CONNECT support over HTTP/2 (#2523)
Closes #2508
2021-05-24 18:20:44 +00:00
Geoffry Song
be9677a1e7 feat(http2): allow HTTP/2 requests by ALPN when http2_only is unset (#2527) 2021-05-19 10:01:20 -07:00
Adam C. Foltzer
960a69a587 feat(error): add Error::is_parse_too_large and Error::is_parse_status methods (#2538)
The discussion in #2462 opened up some larger questions about more comprehensive approaches to the
error API, with the agreement that additional methods would be desirable in the short term. These
methods address an immediate need of our customers, so I would like to get them in first before we
flesh out a future solution.

One potentially controversial choice here is to still return `true` from `is_parse_error()` for
these variants. I hope the naming of the methods make it clear that the new predicates are
refinements of the existing one, but I didn't want to change the behavior of `is_parse_error()`
which would require a major version bump.
2021-05-12 18:30:28 -07:00
Anthony Ramine
68d4e4a3db feat(client): allow HTTP/0.9 responses behind a flag (#2473)
Fixes #2468
2021-03-26 11:25:00 -07:00
Vincent Ricard
48fdaf1606 fix(headers): Support multiple Content-Length values on same line (#2471)
Closes #2470
2021-03-19 10:38:58 -07:00
Ivan Nikulin
2c8121f173 fix(client): HTTP/1 client "Transfer-Encoding" repair code would panic (#2410)
Closes #2409
2021-01-26 10:36:58 -08:00
Sean McArthur
fad42acc79 feat(lib): Upgrade to Tokio 1.0 (#2369)
Closes #2370
2020-12-23 10:36:12 -08:00
Alex Rebert
1dd761c87d fix(http1): ignore chunked trailers (#2357)
Previously, hyper returned an "Invalid chunk end CR" error on chunked
responses with trailers, as described in RFC 7230 Section 4.1.2. This
commit adds code to ignore the trailers.

Closes #2171
2020-12-15 14:23:07 -08:00