Commit Graph

1664 Commits

Author SHA1 Message Date
Oddbjørn Grødem
ce72f73464 feat(lib): remove stream cargo feature (#2896)
Closes #2855
2022-06-23 15:12:24 -07:00
silence-coding
5fa113ebff fix(http1): fix http1_header_read_timeout to use same future (#2891)
Co-authored-by: silence <xxx@email.com>
2022-06-13 13:44:28 -07:00
Oddbjørn Grødem
e9cab49e6e feat(server): remove AddrStream struct (#2869)
remove addrstream type, it provides no benefit over tokio::net::tcpstream

Closes #2850
2022-06-08 16:59:32 -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
evenbetter
f12d4d4aa8 refactor(lib): resolve unused import (#2889) 2022-06-07 08:10:29 -07:00
Kian-Meng Ang
4545c3ef19 docs(proto): fix typos (#2876) 2022-05-30 07:43:39 -07:00
silence-coding
a32658c1ae feat(server): add Connection::http2_max_header_list_size option (#2828)
This allows setting the HTTP/2 `SETTINGS_MAX_HEADER_LIST_SIZE` which advertises to the peer the maximum header size allowed, and internally is enforced.

Closes #2826
2022-05-18 16:52:01 -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
Basti Ortiz
faf24c6ad8 refactor(http1): assorted code readability improvements in h1/conn.rs (#2817)
* refactor: use `matches` macro to flatten code

* refactor: prefer `matches` over explicit matching

* refactor: reuse `can_write_body` method

* refactor: use `matches` over `if`-`let`

* refactor: nested `if`-`else` as early return

* refactor: move inner `match` logic outside

* refactor: unneeded `return` in `match`

* refactor: remove unneeded reference matching

* refactor: use early returns for idle check

* refactor: use `matches` macro for Boolean `match`
2022-04-26 11:29:49 -07:00
Anthony Ramine
6a35c175f2 fix(http1): fix preserving header case without enabling ffi (#2820)
The previous commit broke this, but it wasn't released, so released versions will never notice the breakage.
2022-04-26 08:24:57 -07:00
cui fliter
89598dfcfe docs(lib): fix some typos (#2818)
Signed-off-by: cuishuang <imcusg@gmail.com>
2022-04-25 11:05:48 -07:00
Liam Warfield
78de8914ea feature(ffi): add connection option to preserve header order (#2798)
Libcurl expects that headers are iterated in the same order that they
are recieved. Previously this caused curl tests 580 and 581 to fail.
This necessitated exposing a way to preserve the original ordering of
http headers.

SUMMARY OF CHANGES: Add a new data structure called OriginalHeaderOrder that
represents the order in which headers originally appear in a HTTP
message. This datastructure is `Vec<(Headername, multimap-index)>`.
This vector is ordered by the order which headers were recieved.
Add the following ffi functions:
- ffi::client::hyper_clientconn_options_set_preserve_header_order : An
     ffi interface to configure a connection to preserve header order.
- ffi::client::hyper_clientconn_options_set_preserve_header_case : An
     ffi interface to configure a connection to preserve header case.
- Add a new option to ParseContext, and Conn::State called `preserve_header_order`.
  This option, and all the code paths it creates are behind the `ffi`
  feature flag. This should not change performance of response parsing for
  non-ffi users.

Closes #2780

BREAKING CHANGE: hyper_clientconn_options_new no longer
  sets the http1_preserve_header_case connection option by default.
  Users should now call
  hyper_clientconn_options_set_preserve_header_case
  if they desire that functionality.
2022-04-23 09:05:37 -07:00
Ralf Jung
8834d5a2a7 test(lib): fix tests with more feature combinations 2022-04-21 12:55:52 -07:00
Ilya Trefilov
ffbf610b16 feat(server): add AddrStream::local_addr() (#2816)
Expose local address of tcp connection in AddrStream.

Closes #2773
2022-04-20 15:35:36 -07:00
SabrinaJewson
e3ee1de32d style(server): rustfmt 2022-04-08 17:02:02 -07:00
SabrinaJewson
dd08d9c3e5 refactor(server): simplify server cfgs
`server.rs` is currently littered with `cfg`s for `http1` or `http2`,
since the majority of server behaviour is only available with either one
of those feature flags active. This is hard to maintain and confusing to
read, so this commit extracts the two implementations into their own
files, since there is very little benefit in sharing code between the
two.
2022-04-08 17:02:02 -07:00
SabrinaJewson
0fec1c8737 refactor(server): move non-conn code out of conn.rs
The actual code for `Server` was previously organized very confusingly:
it was thrice layered with `SpawnAll` and `Serve` which both appeared in
conn.rs despite not having anything to do with the lower-level conn API.
This commit changes that, removing all layering and having the code for
the higher-level `Server` appear inside `server.rs` only.
2022-04-08 17:02:02 -07:00
Sean McArthur
740654e55d refactor(error): improve error message when user body ends early 2022-03-14 10:31:31 -07:00
Devrim Şahin
055b4e7ea6 feat(client): add HttpInfo::local_addr() method
This adds `local_addr` information from `TcpStream` to the `HttpInfo` struct

Closes #2767
2022-02-28 14:18:51 -08:00
Stéphan Kochen
6464c0ed49 docs(upgrade): fix typo in upgrade docs (#2765) 2022-02-25 10:28:13 -08:00
Ilya Trefilov
4fcfe1f4ba docs(client): Add tcp feature for Client::new docs
added cfg attr to denote required tcp feature in docs for Client::new method

Closes: #2759
2022-02-15 15:23:15 -08: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
Anthony Ramine
5ec094caa5 feat(client): implement the HTTP/2 extended CONNECT protocol from RFC 8441 (#2682) 2022-02-07 17:35:34 -08:00
David Pedersen
6932896a7f feat(error): add Error::message (#2737)
This adds Error::message which returns the message that is unique to the error, without the message from the source. That way users can create a newtype around hyper::Error and use this in the Display impl to work around #2732.

Closes #2732
2022-02-04 17:10:00 -08:00
Oliver Gould
dcdd6d1090 fix(client): avoid panics in uses of Instant (#2746)
Even though this is almost definitely a bug in Rust, it seems most
prudent to actively avoid the uses of `Instant` that are prone to this
bug.

This change replaces uses of `Instant::elapsed` and `Instant::sub` with
calls to `Instant::saturating_duration_since` to prevent this class of
panic.
2022-01-31 16:33:16 -08:00
Ivan Boldyrev
f1b89c117c refactor(client): use Box<str> inside dns::Name (#2727)
Use Box<str> in hyper::client::connect::dns::Name, so
its size is 16 bytes, not 24 bytes.  As Name never
change its contents, read-only Box<str> is perfectly OK.
2021-12-29 08:33:06 -08:00
Bruce Mitchener
02f3630af6 chore(dependencies): update to itoa 1 2021-12-14 10:55:21 -08:00
Rajin Gill
f44f7265e0 style(http1): correct indentation
Minor reformatting of single block.
2021-12-14 08:01:14 -08:00
Sean McArthur
bff977b73c feat(http2): add http2_max_send_buf_size option to client and server
This value is like a high-water mark. It applies per stream. Once a
stream has buffered that amount of bytes to send, it won't poll more
data from the `HttpBody` until the stream has been able to flush under
it.
2021-12-09 10:06:14 -08: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
Sean McArthur
ce8242571f refactor(lib): resolve unused warnings from server-specific code (#2710) 2021-11-30 10:26:20 -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
a1502e1067 docs(http1): clarify HTTP1 preserve case option 2021-11-16 11:44:21 -08:00
Sean McArthur
a12db28542 docs(upgrade): add module documentation for HTTP upgrades 2021-11-15 14:47:29 -08:00
Ahmed Sobeh
174b553d2d fit(client): cancel blocking DNS lookup if GaiFuture dropped (#2689)
Closes #2686
2021-11-08 14:23:18 -08:00
muvlon
913be88f71 docs(client): fix missing feature attrs in another doctest
when testing my fix for #2687, I noticed that this doctest has the same issue,
so here's another fix.
2021-11-08 10:47:08 -08:00
muvlon
3221f573d2 docs(body) fix doctest failing due to missing features
The doctest uses `hyper::Client`, but that is not available unless these features are enabled.
This commit adds an attribute to check for those and allows `cargo test` with no arguments to pass again.

fixes #2687.
2021-11-08 10:47:08 -08:00
Anthony Ramine
80627141ed feat(http1): Add http1_writev(bool) to client and server Builders
Restore a way to force queue writing strategy.

Closes #2676
2021-11-04 15:29:43 -07:00
Luqman Aden
ab469eb3c6 feat(upgrade): allow http upgrades with any body type
Allow using `Request<T>`/`Response<T>` for any given T with
`upgrade::on` instead of just restricting it to `hyper::Body`.
2021-11-03 11:40:33 -07:00
Alice Ryhl
bd6c35b98f fix(client): make ResponseFuture implement Sync 2021-10-18 10:25:27 -07:00
Sean McArthur
e48519a1e2 refactor(http1): adjust a few tracing event outputs 2021-10-13 17:42:30 -07:00
Sean McArthur
55a61c072d test(client): remove unneeded ipv6 dns parse test 2021-10-13 17:26:36 -07:00
Ryan Goodfellow
910e02687d fix(client): remove ipv6 square brackets before resolving 2021-10-13 15:54:38 -07:00
Rafael Ávila de Espíndola
1d553e52c6 feat(server): Remove Send + Sync requirement for Body in with_graceful_shutdown
Also expand the single threaded example to use that.
2021-10-12 16:47:03 -07:00
Anthony Ramine
6169db250c feat(h2): always include original h2 error on broken pipe 2021-10-04 13:35:07 -07:00
Ivan Tham
7757789589 docs(client): add link and cleanup example for hyper::client::conn (#2533) 2021-09-16 16:31:59 -07:00
Vagelis Prokopiou
0460cd909e docs(body): add example for to_bytes()
cc #2201
2021-09-16 16:25:40 -07:00
Sean McArthur
949216f583 docs(ffi): expand URI documentation 2021-09-16 10:20:40 -07:00