Commit Graph

2493 Commits

Author SHA1 Message Date
Michael Hewson
db32e1050c feat(lib): remove dependency on tracing's log feature (#2342)
Closes #2326

BREAKING CHANGE: hyper no longer emits `log` records automatically.
  If you need hyper to integrate with a `log` logger (as opposed to `tracing`),
  you can add `tracing = { version = "0.1", features = ["log"] }` to activate them.
2020-11-25 12:41:58 -08:00
Eliza Weisman
d6aadb8300 perf(lib): re-enable writev support (#2338)
Tokio's `AsyncWrite` trait once again has support for vectored writes in
Tokio 0.3.4 (see tokio-rs/tokio#3149).

This branch re-enables vectored writes in Hyper for HTTP/1. Using
vectored writes in HTTP/2 will require an upstream change in the `h2`
crate as well.

I've removed the adaptive write buffer implementation
that attempts to detect whether vectored IO is or is not available,
since the Tokio 0.3.4 `AsyncWrite` trait exposes this directly via the
`is_write_vectored` method. Now, we just ask the IO whether or not it
supports vectored writes, and configure the buffer accordingly. This
makes the implementation somewhat simpler.

This also removes `http1_writev()` methods from the builders. These are
no longer necessary, as Hyper can now determine whether or not
to use vectored writes based on `is_write_vectored`, rather than trying
to auto-detect it.

Closes #2320 

BREAKING CHANGE: Removed `http1_writev` methods from `client::Builder`,
  `client::conn::Builder`, `server::Builder`, and `server::conn::Builder`.
  
  Vectored writes are now enabled based on whether the `AsyncWrite`
  implementation in use supports them, rather than though adaptive
  detection. To explicitly disable vectored writes, users may wrap the IO
  in a newtype that implements `AsyncRead` and `AsyncWrite` and returns
  `false` from its `AsyncWrite::is_write_vectored` method.
2020-11-24 10:31:48 -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
Eliza Weisman
751c122589 feat(lib): update bytes to 0.6, update http-body (#2339)
This branch updates `bytes` and `http-body` to the latest versions. The
`http-body` version that uses `bytes` 0.6 hasn't been released yet, so
we depend on it via a git dep for now. Presumably Hyper and `http-body`
will synchronize their releases.

Other than that, this is a pretty mechanical update. Should fix the
build and unblock the `h2` update to use vectored writes.
2020-11-19 16:23:32 -08:00
Sean McArthur
ed2b22a7f6 feat(lib): disable all optional features by default (#2336)
BREAKING CHANGE: All optional features have been disabled by default.
2020-11-19 10:05:39 -08:00
Eliza Weisman
abb6471690 refactor(client): use tokio's TcpSocket for more sockopts (#2335)
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-11-18 14:45:45 -08:00
Sean McArthur
bdb5e5d694 feat(server): Make the server code an optional feature (#2334)
cc #2223 

BREAKING CHANGE: The HTTP server code is now an optional feature. To
  enable the server, add `features = ["server"]` to the dependency in
  your `Cargo.toml`.
2020-11-18 11:02:20 -08:00
Sean McArthur
4e55583d30 feat(client): Make client an optional feature
cc #2223

BREAKING CHANGE: The HTTP client of hyper is now an optional feature. To
  enable the client, add `features = ["client"]` to the dependency in
  your `Cargo.toml`.
2020-11-17 17:06:25 -08:00
Sean McArthur
eb092a7b8c chore(ci): check all feature combinations in CI 2020-11-17 14:30:27 -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
2f2ceb2426 chore(ci): automatically publish benchmarks in a graph 2020-11-16 16:51:30 -08:00
Eliza Weisman
b3b8010e1c refactor(server): simplify drain (#2328)
The current implementation of `drain` uses a `tokio::sync::watch`
channel to send the shutdown signal, and a `tokio::sync::mpsc` to signal
when all draining tasks have completed. No data is ever actually sent on
the MPSC; instead, it is simply used to notify the task that signalled
the drain when all draining tasks have been dropped.

Tokio 0.3's `watch::Sender` has a `closed` method that can be used to
await the dropping of all receivers. This can be used instead of the
MPSC channel. This commit updates `drain` to use `watch::Sender::closed`
instead. This has fewer moving parts, and may have slightly less
overhead (as it doesn't require additional allocation forthe MPSC which
is never actually used).

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-11-12 13:34:19 -08:00
Sean McArthur
b819b428d3 feat(http2): Make HTTP/2 support an optional feature
cc #2251

BREAKING CHANGE: This puts all HTTP/2 methods and support behind an
  `http2` cargo feature, which will not be enabled by default. To use
  HTTP/2, add `features = ["http2"]` to the hyper dependency in your
  `Cargo.toml`.
2020-11-10 13:40:34 -08:00
Evan Cameron
5438e9b7bf docs(example): fix http_proxy comment (#2324) 2020-11-09 08:07:12 -08:00
Eliza Weisman
71f3402421 fix(http1): ending close-delimited body should close (#2322)
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-11-06 15:38:01 -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
Sean McArthur
cc7d3058e8 chore(lib): start 0.14.x development 2020-11-02 16:17:15 -08:00
Sean McArthur
42560c7c40 v0.13.9 2020-11-02 15:20:53 -08:00
Pedro Calado
2a938d96ae fix(server): reschedule keep alive interval timer once a pong is received
`KeepAliveState` did not transition from `PingSent` to `Scheduled` after
a pong was received. This prevented more than one ping to be sent by the
server. This fix checks if `ping_sent_at` has already been cleared by
`Ponger::poll` when `KeepAliveState::PingSent` state is active.

Fixes #2310
2020-10-29 09:02:26 -07: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
Ivan Nikulin
fb19f3a869 feat(client): add HttpConnector::set_local_addresses to set both IPv6 and IPv4 local addrs (#2172)
Currently HttpConnector::set_local_address method accepts a single
argument. Server might not support IPv6 or IPv4. Therefore, the only
solution at the moment is to manually perform DNS resolution and pick
appropriate local address family. This is inefficient, as leads to
2 DNS lookups per request. This commit allows specifying both IPv4
and IPv6, so connector can decide which one to use based on DNS
resolution results.
2020-10-13 16:02:16 -07:00
Taiki Endo
02732bef0c chore(dependencies): update pin-project to 1.0 (#2298) 2020-10-13 11:14:47 -07:00
Steven Fackler
2dc9768d2d feat(client): Add accessors to Connected fields (#2290) 2020-09-29 17:02:31 -07:00
Alexey Kiryushin
01103da5d9 fix(client): fix panic when addrs in ConnectingTcpRemote is empty (#2292)
Closes #2291
2020-09-29 11:07:09 -07:00
Sean McArthur
523d66a41f refactor(body): fix unused sync_wrapper when stream feature disabled (#2287) 2020-09-21 13:57:58 -07:00
Sean McArthur
aea9c52808 v0.13.8 2020-09-18 10:44:16 -07:00
Sean McArthur
d8622e570c refactor(http1): include bytes in invalid header name panic (#2286) 2020-09-18 10:08:44 -07:00
Snarpix
187c22afb5 feat(lib): Setting http1_writev(true) will now force writev queue usage
Previously, calling `http1_writev(true)` would just keep the default behavior, which was to auto detect if writev was optimal. Now, the auto-detection is still default, but explicitly calling `http1_writev(true)` will skip the auto-detection, and always use writev queue strategy.

Closes #2282
2020-09-18 09:50:43 -07:00
Sean McArthur
1edf2af377 docs(client): fix broken intra doc link for http::Uri 2020-09-17 13:44:50 -07:00
Danilo Bargen
58a25eb7dc docs(body): Sender: Add a note about abnormal body closing (#2283) 2020-09-17 11:16:20 -07:00
Stefano Buliani
66fc127c8d docs(server): Example for conn modules (#2277)
Add basic, module-level example for the Http struct in the server::conn module that shows how to customize the configuration of the HTTP protocol handling and then serve requests received through a tokio TCP stream.
2020-08-28 11:21:33 -07:00
João Oliveira
1ecbcbb119 fix(http1): return error if user body ends prematurely
- update proto::h1::end_body to return Result<()>
- update Encoder::end to return Error(NotEof) only when there's Content-length left to be addressed

Closes #2263
2020-08-12 14:12:48 -07:00
Sean McArthur
3de81c822e refactor(h1): add spans for parse_headers and encode_headers (#2262) 2020-08-05 13:52:52 -07:00
João Oliveira
6e7e4e2cd5 docs(client): clarify HttpConnector::new_with_resolver doc (#2255)
link to hyper::client::connect::dns, closes #2254
2020-07-29 09:27:46 -07:00
Sean McArthur
25a05894b9 refactor(h1): use httpdate for server date header 2020-07-28 17:48:32 -07:00
Sean McArthur
48f04b6217 test(h1): add benchmarks for server date checking and rendering 2020-07-28 17:14:15 -07:00
JohnMartin95
f4f14b30e3 chore(dependencies): require tokio 0.2.11 (#2252)
Closes #2250
2020-07-28 16:49:09 -07:00
Theodore DeRego
b5d5e21449 feat(server): implement AsRawFd for AddrStream (#2246)
Fixes #2245.
2020-07-16 08:26:46 -07:00
Sean McArthur
4216b2de70 v0.13.7 2020-07-13 17:03:48 -07:00
Sean McArthur
8f6d0a2f7e docs(readme): replace irc links with discord links 2020-07-10 15:35:02 -07:00
David Barsky
9832aef9ee feat(lib): Move from log to tracing in a backwards-compatible way (#2204)
I've moved Hyper from `log` to `tracing`. Existing `log`-based users shouldn't notice a difference, but `tracing` users will see higher performance when filtering data. This isn't the _end_  of the `tracing` integration that can happen in `Hyper` (e.g., Hyper can start using spans, typed fields, etc.), but _something_ is better than nothing. I'd rather address those points, including examples, in followups.

I've attached a screenshot of the `hello` example working, but the logged information is pulled from `tracing`, not `log`.

<img width="514" alt="Screen Shot 2020-05-16 at 1 23 19 PM" src="https://user-images.githubusercontent.com/2067774/82126298-d8103800-9779-11ea-8f0b-57c632c684d6.png">
2020-07-06 18:30:41 -07:00
Daiki Mizukami
77c3b5bc0c feat(client): impl tower_service::Service for &Client (#2089) 2020-06-25 08:18:05 -07:00
Markus Westerlind
07f2fd1775 refactor(h1): use futures::ready! in a few places 2020-06-23 08:06:39 -07:00
Sean McArthur
981d26d5a1 perf(h2): forward Buf::bytes_vectored to SendBuf 2020-06-16 00:08:37 +00:00
Thomas
55ba000746 docs(service): add example of impl Service (#2209)
Add `examples/service_struct_impl.rs`, which provides an up-to-date
example of implementing MakeService and Service on custom types.
The `Svc` struct has a Counter, which demonstrates how to instantiate
shared resources in the `MakeSvc` and pass the resource to the
services. Updates the `examples/README.md` and the doc in
`src/service/mod.rs`.

Closes #1691
2020-06-15 12:01:04 -07:00
Damien Elmes
0d0d363547 fix(client): don't panic in DNS resolution when task cancelled (#2229)
If the runtime is dropped while a DNS request is being made, it can
lead to a panic. This patch checks if the task was cancelled, and
returns a generic IO error instead of panicking in that case.

The following code reproduces the problem on my macOS machine:

```
use hyper::Client;
use tokio::runtime;

type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;

fn main() {
    let rt = runtime::Builder::new()
        .threaded_scheduler()
        .core_threads(1)
        .enable_all()
        .build()
        .unwrap();

    // spawn a request and then drop the runtime immediately
    rt.spawn(fetch_url());
}

async fn fetch_url() -> Result<()> {
    let url: hyper::Uri = "http://example.com".parse()?;
    let client = Client::builder().build_http::<hyper::Body>();

    let res = client.get(url).await?;
    println!("Response: {}", res.status());

    Ok(())
}
```
2020-06-11 13:36:17 -07:00
Taiki Endo
9998f0fd0b refactor(lib): remove pin related unsafe code (#2220) 2020-06-08 16:02:14 -07:00
Taiki Endo
d5d09ed753 refactor(lib): Remove uses of pin_project::project attribute (#2219)
pin-project will deprecate the project attribute due to some unfixable
limitations.

Refs: https://github.com/taiki-e/pin-project/issues/225
2020-06-05 16:53:58 -07:00
Geoffry Song
2354a7eec3 feat(http2): configure HTTP/2 frame size in the high-level builders too (#2214)
Oops, I missed this in #2211.
2020-06-02 19:45:12 -07:00
Sean McArthur
b6fb18aee0 v0.13.6 2020-05-29 11:55:20 -07:00