pub struct Http { /* private fields */ }Expand description
A Transport that fetches over HTTP and HTTPS, behind the crate’s http feature.
TLS is rustls with Mozilla’s root certificates compiled in (the webpki-roots crate), so it
needs no OpenSSL and ignores the operating system’s certificate store. It follows up to ten
redirects and sends Accept-Encoding: gzip, unpacking gzip bodies. Any status but 2xx is an
error, as are a timeout and a body that unpacks to more than the limit. An HTTP or HTTPS proxy
from the environment is used. A SOCKS one is refused with an error rather than bypassed, since
this build cannot speak SOCKS; hosts NO_PROXY exempts are fetched directly, with no redirect
followed, since the next address might not be exempt.
Cloning is cheap and the clones share one pool of connections.
use hpr_net::{Cache, Client, Http, Mode, Source};
let dir = Cache::platform_dir().expect("a home or local app data folder");
let client = Client::new(Http::new(), Cache::new(dir), Mode::Online);
let source = Source {
name: "Example".into(),
attribution: "Example data".into(),
ttl_s: 3600,
};
let now_s = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map_or(0, |d| d.as_secs());
let answer = client.fetch(&source, "https://example.com/", now_s)?;
println!("{} bytes, {:?}", answer.body.len(), answer.freshness);Implementations§
Source§impl Http
impl Http
Sourcepub const USER_AGENT: &str = "hpr-sim/0.1.0 (+https://github.com/nrdptel/hpr-sim)"
pub const USER_AGENT: &str = "hpr-sim/0.1.0 (+https://github.com/nrdptel/hpr-sim)"
The User-Agent header sent: the crate’s name and version and the project’s address, so a
data provider can tell who is calling.
Sourcepub const MAX_TIMEOUT: Duration
pub const MAX_TIMEOUT: Duration
The longest timeout used: 30 days. A longer one, such as Duration::MAX for “none”,
counts as this, since a deadline past the clock’s range would overflow.
Sourcepub fn new() -> Self
pub fn new() -> Self
A transport with HttpConfig::default.
Sourcepub fn with_config(config: HttpConfig) -> Self
pub fn with_config(config: HttpConfig) -> Self
A transport with config.