145 Commits

Author SHA1 Message Date
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
Lin Yihai
0bd4adfed2 refactor(lib): reduce clippy warnings (#3805) 2024-12-06 11:04:54 -05: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
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
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
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
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
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
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
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
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
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
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
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
Jannes (思明)
67b73138f1 fix(server): don't add implicit content-length to HEAD responses (#2836)
HEAD responses should not have content-length implicitly set by hyper.

Co-authored-by: Jannes Timm <jannes@cloudflare.com>
2022-05-18 10:49:58 -07:00
Sean McArthur
84b78b6c87 fix(http2): received Body::size_hint() now return 0 if implicitly empty (#2715)
An HTTP/2 stream may include a set of headers, and a flag signalling
END-STREAM, even if a `content-length` isn't included. hyper wouldn't
notice, and so the `Body` would report a size-hint of `0..MAX`. hyper
now notices that the stream is ended, and couldn't possibly include any
bytes for the body, and thus will give a size-hint of `0` exactly.
2021-12-06 14:14:41 -08:00
Jonathan Murray
7435cc3399 fix(server): use case-insensitive comparison for Expect: 100-continue (#2709)
According to rfc2616#section-14.20 the header value is case-insensitive. Certain clients send the expectation as `100-Continue` and this should be handled by the server.

Closes #2708
2021-11-30 08:58:50 -08:00
Rajin Gill
5f938fffa6 fix(http1): return 414 when URI contains more than 65534 characters (#2706)
Previous behavior returned a 404 Bad Request. Conforms to HTTP 1.1 RFC.

Closes #2701
2021-11-29 12:31:41 -08:00
Paolo Barbolini
842c6553a5 feat(server): add HTTP/1 header read timeout option (#2675)
Adds `Server::http1_header_read_timeout(Duration)`. Setting a duration will determine how long a client has to finish sending all the request headers before trigger a timeout test. This can help reduce resource usage when bad actors open connections without sending full requests.

Closes #2457
2021-11-18 12:02:06 -08:00
Sean McArthur
1fb719e0b6 fix(http1): reject content-lengths that have a plus sign prefix
The HTTP/1 content-length parser would accept lengths that were prefixed
with a plus sign (for example, `+1234`). The specification restricts the
content-length header to only allow DIGITs, making such a content-length
illegal. Since some HTTP implementations protect against that, and
others mis-interpret the length when the plus sign is present, this
fixes hyper to always reject such content lengths.

See GHSA-f3pg-qwvg-p99c
2021-07-07 11:33:08 -07:00
Sean McArthur
1068b994df fix(http1): protect against overflow in chunked decoder
The HTTP/1 chunked decoder, when decoding the size of a chunk, could
overflow the size if the hex digits were too large. This fixes it by
adding an overflow check in the decoder.

See GHSA-5h46-h7hh-c6x9
2021-07-07 11:33:08 -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
Peter Smit
8cbf9527df fix(server): skip automatic Content-Length headers when not allowed (#2216)
Closes #2215
2021-03-04 17:03:33 -08:00
Sean McArthur
121c33132c feat(upgrade): Moved HTTP upgrades off Body to a new API (#2337)
Closes #2086

BREAKING CHANGE: The method `Body::on_upgrade()` is gone. It is
  essentially replaced with `hyper::upgrade::on(msg)`.
2020-11-19 16:36:12 -08:00
Sean McArthur
2a19ab74ed feat(http1): Make HTTP/1 support an optional feature
cc #2251

BREAKING CHANGE: This puts all HTTP/1 methods and support behind an
  `http1` cargo feature, which will not be enabled by default. To use
  HTTP/1, add `features = ["http1"]` to the hyper dependency in your
  `Cargo.toml`.
2020-11-17 10:42:20 -08:00
Sean McArthur
1b9af22fa0 Tokio 0.3 Upgrade (#2319)
Co-authored-by: Urhengulas <johann.hemmann@code.berlin>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2020-11-05 17:17:21 -08:00
Pedro Calado
f288641792 test(server): test server keep alive by counting number of pings
Add `http2_keep_alive_count_server_pings` which tests if 3 pings are
received under 5 seconds with keep alive interval set to 1 second.
2020-10-29 09:02:26 -07:00
Dirkjan Ochtman
aac0e2dd57 refactor(body): use HttpBody with extra bounds instead of Payload trait 2020-05-14 13:26:39 -07:00