#hyper #timeout #offers #connection #connector #connect #network-connector

hyper-timeout-connector

A Hyper NetworkConnector which offers a connection timeout

1 unstable release

Uses old Rust 2015

0.1.0 Jun 13, 2017

#41 in #offers

MIT/Apache

7KB
81 lines

hyper-timeout-connector

Build Status

Documentation

A Hyper NetworkConnector which offers a connection timeout.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

A Hyper NetworkConnector which offers a connection timeout.

Hyper's default HttpConnector does not offer a configurable timeout for the establishment of new connections, so connect calls may block for long periods of time if some addresses don't respond. The HttpTimeoutConnector allows an upper bound to be placed on the time taken by the connection process.

Note

The timeout is applied separately to each of the IP addresses associated with the host.

Examples

Connecting to HTTP sites:

extern crate hyper;
extern crate hyper_timeout_connector;

use hyper::Client;
use hyper_timeout_connector::HttpTimeoutConnector;
use std::time::Duration;

fn main() {
    let mut connector = HttpTimeoutConnector::new();
    connector.set_connect_timeout(Some(Duration::from_secs(30)));
    let client = Client::with_connector(connector);

    let response = client.get("http://google.com").send().unwrap();
}

Connecting to HTTPS sites:

extern crate hyper;
extern crate hyper_timeout_connector;

use hyper::Client;
use hyper::net::HttpsConnector;
use hyper_timeout_connector::HttpTimeoutConnector;
use std::time::Duration;

fn main() {
    let mut connector = HttpTimeoutConnector::new();
    connector.set_connect_timeout(Some(Duration::from_secs(30)));

    let ssl_client = make_ssl_client();
    let connector = HttpsConnector::with_connector(ssl_client, connector);
    let client = Client::with_connector(connector);

    let response = client.get("https://google.com").send().unwrap();
}

Dependencies

~5MB
~107K SLoC