Skip to main content

Http

Struct Http 

Source
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

Source

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.

Source

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.

Source

pub fn new() -> Self

A transport with HttpConfig::default.

Source

pub fn with_config(config: HttpConfig) -> Self

A transport with config.

Trait Implementations§

Source§

impl Clone for Http

Source§

fn clone(&self) -> Http

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Http

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Http

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Transport for Http

Source§

fn get(&self, url: &str) -> Result<Vec<u8>, String>

The body at url. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Http

§

impl !UnwindSafe for Http

§

impl Freeze for Http

§

impl Send for Http

§

impl Sync for Http

§

impl Unpin for Http

§

impl UnsafeUnpin for Http

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.