Commit Graph

203 Commits

Author SHA1 Message Date
Adam C. Foltzer 20fa5c9dbf 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 (思明) e59da72f7f 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
Anthony Ramine 253394a356 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 6a99141968 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 7364d7c578 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 db73bb99dd 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
Sean McArthur 72f2402edb test(client): refactor client helper macro to handle options better 2021-11-24 14:26:26 -08:00
Paolo Barbolini b5200ee1f6 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 012011ca81 test(client): fix extra semi-colon warning in helper macro 2021-08-04 11:45:03 -07:00
Sean McArthur 2f35984810 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 7d2d248d84 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 8a20968ac3 feat(http2): Implement Client-side CONNECT support over HTTP/2 (#2523)
Closes #2508
2021-05-24 18:20:44 +00:00
Geoffry Song 623e355a9f 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 ae867c6cba 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 a88ec66ac3 feat(client): allow HTTP/0.9 responses behind a flag (#2473)
Fixes #2468
2021-03-26 11:25:00 -07:00
Vincent Ricard fa5d7784e9 fix(headers): Support multiple Content-Length values on same line (#2471)
Closes #2470
2021-03-19 10:38:58 -07:00
Peter Smit f6906b8f3b fix(server): skip automatic Content-Length headers when not allowed (#2216)
Closes #2215
2021-03-04 17:03:33 -08:00
Ivan Nikulin 68b39b132b fix(client): HTTP/1 client "Transfer-Encoding" repair code would panic (#2410)
Closes #2409
2021-01-26 10:36:58 -08:00
Sean McArthur 4e6bb01ae9 feat(lib): Upgrade to Tokio 1.0 (#2369)
Closes #2370
2020-12-23 10:36:12 -08:00
Alex Rebert 7899368083 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
Sean McArthur 31492f8fab 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 ac9e1847f1 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 2aad6e18c6 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 78e677ca86 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 e413578820 refactor(body): use HttpBody with extra bounds instead of Payload trait 2020-05-14 13:26:39 -07:00
Sean McArthur 85caec095e feat(http2): add HTTP2 keep-alive support for client and server
This adds HTTP2 keep-alive support to client and server connections
based losely on GRPC keep-alive. When enabled, after no data has been
received for some configured interval, an HTTP2 PING frame is sent. If
the PING is not acknowledged with a configured timeout, the connection
is closed.

Clients have an additional option to enable keep-alive while the
connection is otherwise idle. When disabled, keep-alive PINGs are only
used while there are open request/response streams. If enabled, PINGs
are sent even when there are no active streams.

For now, since these features use `tokio::time::Delay`, the `runtime`
cargo feature is required to use them.
2020-03-20 14:20:45 -07:00
Sean McArthur 6197fa2696 fix(http1): try to drain connection buffer if user drops Body 2020-03-10 12:57:36 -07:00
Sean McArthur 8a1cf4b22d feat(client): rename client::Builder pool options (#2142)
- Renamed `keep_alive_timeout` to `pool_idle_timeout`.
- Renamed `max_idle_per_host` to `pool_max_idle_per_host`.
- Deprecated `keep_alive(bool)` due to confusing name. To disable the
  connection pool, call `pool_max_idle_per_host(0)`.
2020-02-27 14:25:06 -08:00
Sean McArthur c8bdd967a3 style(lib): apply latest rustfmt 2020-02-06 11:41:25 -08:00
Linus Färnstrand fd4c796cdd style(lib): use just std instead of ::std in paths (#2101) 2020-01-29 10:25:57 -08:00
Sean McArthur 3405119392 fix(http1): only send 100 Continue if request body is polled
Before, if a client request included an `Expect: 100-continue` header,
the `100 Continue` response was sent immediately. However, this is
problematic if the service is going to reply with some 4xx status code
and reject the body.

This change delays the automatic sending of the `100 Continue` status
until the service has call `poll_data` on the request body once.
2020-01-28 17:32:58 -08:00
Sean McArthur e1ffa67ebf fix(http1): remove panic for HTTP upgrades that have been ignored (#2115)
Closes #2114
2020-01-23 16:41:40 -08:00
danieleades 0f66461ffd style(lib): address most clippy lints 2020-01-03 09:40:32 -08:00
Vivek Ghaisas ddd5af9c08 style(comments): correct some typos in Rust code comments 2019-12-20 10:16:36 -08:00
Sean McArthur cd21a71693 feat(body): implement HttpBody for Request and Response
When the body type of a `Request` or `Response` implements `HttpBody`,
the `Request` or `Response` itself now implements `HttpBody`.

This allows writing things like `hyper::body::aggregate(req)` instead of
`hyper::body::aggregate(req.into_body())`.

Closes #2067
2019-12-13 10:48:30 -08:00
Sean McArthur 4a39b2f744 fix(http1): fix response with non-chunked transfer-encoding to be close-delimited
Closes #2058
2019-12-12 14:26:56 -08:00
Sean McArthur 2735f41dd1 feat(body): add body::aggregate and body::to_bytes functions
Adds utility functions to `hyper::body` to help asynchronously
collecting all the buffers of some `HttpBody` into one.

- `aggregate` will collect all into an `impl Buf` without copying the
  contents. This is ideal if you don't need a contiguous buffer.
- `to_bytes` will copy all the data into a single contiguous `Bytes`
  buffer.
2019-12-06 10:03:05 -08:00
Sean McArthur 2fd8e2de13 feat(body): replace Chunk type with Bytes
Closes #1931

BREAKING CHANGE: All usage of `hyper::Chunk` should be replaced with
  `bytes::Bytes` (or `hyper::body::Bytes`).
2019-12-05 17:22:13 -08:00
Sean McArthur ea12e15095 style(lib): run rustfmt and enforce in CI 2019-12-05 13:55:17 -08:00
Sean McArthur 8d075b5595 chore(CI): enable GitHub Actions 2019-12-05 13:12:35 -08:00
Sean McArthur 2154aa29ca feat(lib): rename unstable-stream feature to stream and enable by default
Closes #2034
2019-12-04 17:09:10 -08:00
Sean McArthur faf6a64531 chore(dependencies): update to http-body 0.3 2019-12-04 16:48:06 -08:00
Sean McArthur baa998929b feat(client): change connectors to return an impl Connection
Instead of returning a tuple `(impl AsyncRead + AsyncWrite, Connected)`,
this adds a new trait, `hyper::client::connect::Connection`, which
allows querying the connection type for a `Connected`.

BREAKING CHANGE: Connectors no longer return a tuple of
  `(T, Connected)`, but a single `T: Connection`.
2019-12-04 16:15:28 -08:00
Sean McArthur 3918e346b6 feat(client): remove Destination for http::Uri in connectors
BREAKING CHANGE: All usage of `hyper::client::connect::Destination`
  should be replaced with `http::Uri`.
2019-12-04 16:15:28 -08:00
Sean McArthur 46a0f1762c feat(lib): update Tokio, bytes, http, h2, and http-body 2019-12-04 10:56:34 -08:00
Daniel Johnson c6275ce668 chore(dependencies): update futures to 0.3.1 2019-11-14 10:04:16 -08:00
Sean McArthur 837ac65f1e feat(client): change Resolve to be Service<Name>
Closes #1903

BREAKING CHANGE: The `Resolve` trait is gone. All custom resolves should
  implement `tower::Service` instead.

  The error type of `HttpConnector` has been changed away from
  `std::io::Error`.
2019-11-12 13:08:39 -08:00
Sean McArthur ba38ea2e89 feat(client): change Connect trait into an alias for Service
The `Connect` trait is now essentially an alias for
`Service<Destination>`, with a blanket implementation as such, and is
sealed.

Closes #1902

BREAKING CHANGE: Any manual implementations of `Connect` must instead
  implement `tower::Service<Destination>`.
2019-10-22 14:40:23 -07:00
Sean McArthur 9d8cdc43b3 fix(server): ignore expect-continue with no body in debug mode
Closes #1843
2019-10-18 15:44:01 -07:00
Sean McArthur 8eef9e09be refactor(http1): notice eof in the try_keep_alive method 2019-10-18 15:16:07 -07:00