Skip to main content

FetchRequest

Struct FetchRequest 

Source
pub struct FetchRequest<'a> {
    pub target: Target<'a>,
    pub priority: Priority,
    pub validators: Option<&'a Validators>,
    pub max_size: Option<u64>,
    pub headers: &'a [(String, String)],
    pub basic_auth: Option<&'a BasicAuth>,
    pub allow_cleartext_credentials: bool,
    pub max_error_body: Option<u64>,
}
Expand description

The request of one fetch.

The Debug output shows the name of each header, and <redacted> in place of its value. The target shows as the Debug output of Target shows it.

Fields§

§target: Target<'a>

The target: a path under the base URL of each mirror, the same with a query string, or an absolute URL.

The fetcher adds a path to the base path as written, so the path carries the escapes that the server expects. A path holds no ? and no #, because neither is part of a path. Either one fails the fetch before admission. If the fetcher has a signer, the fetcher adds the path that RequestSigner::request_path gives in place of the path.

The fetcher adds ? and the query of Target::PathQuery after the path, as written, so the query carries the escapes that the server expects. A query holds no #, because a # starts a fragment. A # fails the fetch before admission.

The fetcher sends the query string of a URL as written. A fragment in a URL fails the fetch, because no request sends a fragment. A character that a request target cannot hold fails the fetch when the fetcher assembles the URL.

§priority: Priority

The place of the request in the queue when the fetcher is at its limit.

§validators: Option<&'a Validators>

The validators of a previous fetch.

If the server reports that the copy is still current, the fetch gives Fetched::NotModified.

§max_size: Option<u64>

The largest response body, in bytes, that the fetch accepts.

A larger Content-Length fails the fetch with Error::FetchTooLarge. If a body grows past the cap while it streams, the read fails with io::ErrorKind::FileTooLarge. The fetcher compares the cap with the response that answers, and does not measure an intermediate redirect response.

§headers: &'a [(String, String)]

Headers merged over the headers of the fetcher.

An entry replaces a fetcher header of the same name. Names compare as HeaderName, so the comparison ignores case. Two entries of one name both go on the wire. An invalid name or value fails the fetch before admission.

The fetcher sets User-Agent and Accept-Encoding: identity, and an entry of one of these names replaces the value. An entry can ask for a content coding. A response that declares a coding fails with Error::ContentEncoded, whichever layer asked for it.

A Range entry, in either layer, makes a 206 a successful answer. The fetch then gives the part of the object as a Body, whose status is 206. A 206 to a request with no Range entry fails the fetch with Error::HttpStatus. The size cap and the content coding rules apply to a 206 as to a 200.

A Host entry fails the fetch, because the header comes from the URL. A header that the connection layer sets fails at both layers: a framing name or a hop-by-hop name. The connection owns the framing of a request and the state of its connection. A value of the caller puts the wire and the connection pool out of step.

§Authorization

The request carries the Authorization header of the first of these that is set:

  1. FetchRequest::basic_auth
  2. an Authorization entry in these headers
  3. FetcherOptions::basic_auth or FetcherOptions::bearer_token
  4. an Authorization entry in FetcherOptions::headers.

Credentials beside an Authorization header in one layer give two answers to one question. Fetcher::new refuses them on the fetcher, and the fetch refuses them on a request.

A fetcher with a signer takes no credential of a request. basic_auth or an Authorization entry in these headers then fails the fetch before admission with Error::Fetch. Fetcher::new refuses layers 3 and 4 beside a signer. So the signature is the one credential of the request, and each header that the signer returns replaces the header of the same name.

§basic_auth: Option<&'a BasicAuth>

Credentials that replace the credentials of the fetcher for this request.

These set the Authorization header, so an Authorization entry in headers beside them fails the fetch. A signer of the fetcher beside them also fails the fetch before admission with Error::Fetch.

The fetcher encodes the header value for each request. A caller that sends one credential over many requests can encode the Authorization value once and set it in headers. That entry replaces the credential of the fetcher for the request in the same way.

§allow_cleartext_credentials: bool

The permission for a credential to reach a cleartext origin.

If this is false and the merged headers carry a credential, the fetch fails if a destination that it can reach is http. The merged headers include the credentials of the fetcher. The check of Fetcher::new on the mirror list applies whatever this value is. The default is false.

FetcherOptions::allow_cleartext_credentials lifts this refusal for each request of the fetcher.

A redirect hop never carries a credential to a cleartext origin of its own. The fetcher removes the credential for a hop at another origin, and refuses a hop from https to http. Fetcher::fetch states the redirect rules.

§Cleartext credentials

The fetcher withholds a credential from no destination that a route names. So it refuses a credential and a cleartext destination together. The credentials are basic_auth, and an Authorization, Proxy-Authorization, or Cookie entry in the merged headers. FetcherOptions::basic_auth and FetcherOptions::bearer_token are Authorization entries in the merged headers. FetcherOptions::signer is also a credential.

If a fetch carries a credential and a destination that it can reach is http, the fetch fails before admission with Error::Fetch. The message names that origin. The other choice is to withhold the credential from that one destination. That choice turns a configuration mistake into a 401 that names nothing.

§max_error_body: Option<u64>

The largest body of an unsuccessful response that the fetch keeps.

With Some(cap), a fetch that fails with Error::HttpStatus gives the headers of the reported response in that error. It also gives the body, if the whole body is cap bytes or less. Some(0) keeps the headers and an empty body. ErrorResponse states when the body is absent.

None keeps nothing, and the fetch discards each unsuccessful response. The default is None.

Fetcher::fetch states the rules in its section “Error responses”.

Implementations§

Source§

impl<'a> FetchRequest<'a>

Source

pub fn path(path: &'a str) -> FetchRequest<'a>

Creates a request for path under each mirror.

The request has normal priority, no validators, and no size cap. It carries the headers and the credentials of the fetcher.

Source

pub fn path_query(path: &'a str, query: &'a str) -> FetchRequest<'a>

Creates a request for path with the query string query under each mirror.

The query has no leading ?. The request has normal priority, no validators, and no size cap. It carries the headers and the credentials of the fetcher.

Source

pub fn url(url: &'a str) -> FetchRequest<'a>

Creates a request for the absolute URL url.

The request has normal priority, no validators, and no size cap. It carries the headers and the credentials of the fetcher.

Trait Implementations§

Source§

impl<'a> Clone for FetchRequest<'a>

Source§

fn clone(&self) -> Self

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 FetchRequest<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Forget for FetchRequest<'a>

§

impl<'a> Freeze for FetchRequest<'a>
where &'a str: Freeze, &'a Validators: Freeze, &'a [(String, String)]: Freeze, &'a BasicAuth: Freeze,

§

impl<'a> Move for FetchRequest<'a>

§

impl<'a> RefUnwindSafe for FetchRequest<'a>

§

impl<'a> Send for FetchRequest<'a>
where &'a str: Send, &'a Validators: Send, &'a [(String, String)]: Send, &'a BasicAuth: Send,

§

impl<'a> Sync for FetchRequest<'a>
where RawVecInner: Sync,

§

impl<'a> Unpin for FetchRequest<'a>
where &'a str: Unpin, &'a Validators: Unpin, &'a [(String, String)]: Unpin, &'a BasicAuth: Unpin,

§

impl<'a> UnsafeUnpin for FetchRequest<'a>

§

impl<'a> UnwindSafe for FetchRequest<'a>

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
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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more