Commit Graph

39 Commits

Author SHA1 Message Date
Sean McArthur
ca99e23e27 refactor(client): clean up unused lint warnings in dns module (#2931) 2022-07-29 16:22:29 -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
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
Ahmed Sobeh
174b553d2d fit(client): cancel blocking DNS lookup if GaiFuture dropped (#2689)
Closes #2686
2021-11-08 14:23:18 -08: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
Jonas Platte
a81c44f2c8 refactor(lib): Import tracing macros per-module
Instead of one #[macro_use] at the crate root.
2021-08-31 16:35:52 -07:00
Taiki Endo
f0ddb66932 refactor(lib): apply unreachable_pub lint (#2400)
Closes #2390
2021-01-14 09:57:55 -08:00
Sean McArthur
b4e24332a0 feat(client): change DNS Resolver to resolve to SocketAddrs (#2346)
The DNS resolver part of `HttpConnector` used to require resolving to
`IpAddr`s, and this changes it so that they resolve to `SocketAddr`s.
The main benefit here is allowing for resolvers to set the IPv6 zone ID
when resolving, but it also just more closely matches
`std::net::ToSocketAddrs`.

Closes #1937

BREAKING CHANGE: Custom resolvers used with `HttpConnector` must change
  to resolving to an iterator of `SocketAddr`s instead of `IpAddr`s.
2020-12-03 14:21:19 -08: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
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
Sean McArthur
57ef271500 docs(lib): fix broken intra docs links 2019-12-11 13:23:36 -08:00
Sean McArthur
0dc89680cd style(lib): run rustfmt and enforce in CI 2019-12-05 13:55:17 -08:00
Sean McArthur
319e8aee15 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
Markus Westerlind
30ac01c180 refactor(client): use async/await in HttpConnector (#2019)
Closes #1984
2019-12-04 13:39:56 -08:00
Sean McArthur
cb3f39c2dc feat(lib): update Tokio, bytes, http, h2, and http-body 2019-12-04 10:56:34 -08:00
James Le Cuirot
131962c86a feat(client): filter remote IP addresses by family of given local IP address
It is not possible to connect to an IPv4 address from an IPv6 address or
vice-versa so don't waste time trying. If no remote addresses match then a
"missing connect error" will now occur.
2019-11-19 10:36:07 -08:00
Sean McArthur
9d9233ce7c 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
f71304b449 refactor(client): use pin_project for Resolve futures 2019-10-23 14:37:03 -07:00
Steven Fackler
4179297ac9 feat(client): Add connect timeout to HttpConnector (#1972)
This takes the same strategy as golang, where the timeout value is
divided equally between the candidate socket addresses.

If happy eyeballs is enabled, the division takes place "below" the
IPv4/IPv6 partitioning.
2019-10-14 11:48:17 -07:00
Sean McArthur
5b348b821c feat(lib): add optional tcp feature, split from runtime
The `HttpConnector` and `AddrListener` types which make use of
`tokio::tcp` have been made their own optional feature. This allows
using them without requiring the *full* tokio runtime.
2019-10-01 10:15:46 -07:00
Sean McArthur
049b5132db feat(client): change GaiResolver to use a global blocking threadpool
BREAKING CHANGE: Calls to `GaiResolver::new` and `HttpConnector::new` no
  longer should pass an integer argument for the number of threads.
2019-08-29 14:16:43 -07:00
Daniel Johnson
536779e16c refactor(dns): migrate deprecated trim_{left,right} -> trim_{start,end} 2019-08-29 11:12:56 -07:00
Sean McArthur
49b12c415d refactor(lib): fix remaining lint warnings (besides tests) 2019-08-22 13:57:50 -07:00
Sean McArthur
7b1d6d71b7 refactor(lib): fix many lint warnings 2019-08-21 11:58:02 -07:00
lzutao
fc7f81b67c style(lib): use rust 2018 edition idioms (#1910) 2019-08-21 11:22:07 -07:00
Douman
4920f5e264 chore(dependencies): Upgrade tokio 2019-08-19 09:00:21 -07:00
Sean McArthur
3524db9473 refactor(client): use a tokio-threadpool for the GaiResolver 2019-07-10 16:11:05 -07:00
Sean McArthur
8f4b05ae78 feat(lib): update to std::future::Future
BREAKING CHANGE: All usage of async traits (`Future`, `Stream`,
`AsyncRead`, `AsyncWrite`, etc) are updated to newer versions.
2019-07-09 15:55:22 -07:00
Sean McArthur
01c03db7ea chore(lib): add dyn keyword to trait objects (#1820)
Requires Rust 1.27.
2019-06-03 13:08:13 -07:00
Sean McArthur
18f022c70b docs(lib): fix several broken links throughout docs
Closes #1749
Closes #1750
2019-01-24 11:20:22 -08:00
Sean McArthur
c328c62ec2 fix(client): parse IPv6 hosts correctly in HttpConnector 2019-01-23 11:24:26 -08:00
Linus Färnstrand
be5ec45571 feat(client): Add useful trait impls to Name 2019-01-11 10:01:28 -08:00
Linus Färnstrand
607c4da0b9 feat(client): add FromStr impl for Name 2019-01-10 09:39:26 -08:00
Sean McArthur
deaa5d1aa9 chore(client): fix infinite recursion in TokioThreadpoolGaiResolver::new 2018-10-23 13:34:47 -07:00
Sean McArthur
34d780acd0 feat(dns): export client::connect::dns module, and
`TokioThreadpoolGaiResolver` type.
2018-10-23 12:49:56 -07:00
Steven Fackler
1e8d6439cf feat(dns): tokio_threadpool::blocking resolver
Unlike the default resolver, this avoids spawning extra dedicated
threads but only works on the multi-threaded Tokio runtime.

Closes #1676
2018-10-23 09:57:04 -07:00
Sean McArthur
2d5af177c1 feat(client): add Resolve, used by HttpConnector
This introduces a `Resolve` trait to describe asynchronous DNS
resolution. The `HttpConnector` can be configured with a resolver,
allowing a user to still use all the functionality of the
`HttpConnector`, while customizing the DNS resolution.

To prevent a breaking change, the `HttpConnector` has its `Resolve`
generic set by default to `GaiResolver`. This is same as the existing
resolver, which uses `getaddrinfo` inside a thread pool.

Closes #1517
2018-10-18 12:10:15 -07:00
Sean McArthur
5bfc110538 refactor(client): improve connect module structure 2018-09-27 14:50:11 -07:00