pub struct FetcherOptions {Show 16 fields
pub mirrors: Vec<String>,
pub headers: Vec<(String, String)>,
pub basic_auth: Option<BasicAuth>,
pub bearer_token: Option<BearerToken>,
pub signer: Option<Arc<dyn RequestSigner>>,
pub allow_cleartext_credentials: bool,
pub tls: TlsOptions,
pub proxy: Proxy,
pub http2: bool,
pub max_retries: u32,
pub max_redirects: u32,
pub max_outstanding: usize,
pub connect_timeout: Duration,
pub progress_timeout: Duration,
pub low_speed: Option<LowSpeed>,
pub fetch_timeout: Option<Duration>,
}Expand description
The options of a Fetcher: the remote, the credentials, and the limits.
FetcherOptions::default sets each field to the default that the field
states. FetcherOptions::new also sets one mirror.
The Debug output shows the name of each header, and <redacted> in
place of its value. The output also shows no password of basic_auth, no
token of bearer_token, no client key or passphrase, and no userinfo of a
proxy URL. Each mirror URL shows with no userinfo. A query shows as
?<redacted>, and a fragment shows as #<redacted>. The signer shows as
its own Debug output shows it.
Fields§
§mirrors: Vec<String>The base URLs, tried in order for each request that names a
Target::Path or a Target::PathQuery.
A remote with a mirror list gives one entry for each mirror. A base URL
is a scheme, an authority, and a path. A query string or userinfo fails
Fetcher::new, so neither part of a base URL reaches the wire. A
request target is the base path, then / and the request path, then
? and the query of a Target::PathQuery. With a
signer, the request path is the path that
RequestSigner::request_path gives.
An empty list serves Target::Url requests alone. The default is an
empty list.
headers: Vec<(String, String)>The extra headers of each request, to each destination and redirect hop.
A request header of the same name replaces an entry. The fetcher sets
User-Agent and Accept-Encoding: identity, and an entry of one of
these names replaces the value of the fetcher. Other headers go as
written. The default is an empty list.
An Authorization, Proxy-Authorization, or Cookie header is a
credential, because its value is a secret, whatever it holds. A
credential goes to the origin that the route names, and to a redirect hop
at that origin alone.
Fetcher::new refuses these entries:
- a credential header, if a mirror is cleartext
httpandallow_cleartext_credentialsisfalse - a
Hostheader - a header that the connection layer sets: a framing name or a hop-by-hop name
- an
Authorizationheader besidebasic_auth - an
Authorizationheader besidebearer_token - an
Authorizationheader besidesigner - an invalid header name or value.
basic_auth: Option<BasicAuth>The credentials for Authorization: Basic, sent with each request.
The credentials go to each destination, and to a redirect hop at the
origin that the route names. FetchRequest::basic_auth replaces them
for one request. The default is None.
Each mirror must be https, unless
allow_cleartext_credentials
is true. Fetcher::new refuses a cleartext mirror, so the
credentials go in cleartext only with that permission. An
Authorization entry in headers, a
bearer_token, or a
signer beside these also fails
Fetcher::new, because each of them can set the same header.
bearer_token: Option<BearerToken>The token for Authorization: Bearer, sent with each request.
The token goes to each destination, and to a redirect hop at the origin
that the route names. Each of these replaces it for one request:
FetchRequest::basic_auth, UploadRequest::basic_auth,
UploadRequest::bearer_token, or an Authorization entry in the
headers of the request. The default is None.
Fetcher::new refuses a token that does not have the token68 syntax
that BearerToken states. It also refuses the token beside
basic_auth, beside an
Authorization entry in headers, or
beside a signer, because each of them can
set the same header.
Each mirror must be https, unless
allow_cleartext_credentials
is true.
signer: Option<Arc<dyn RequestSigner>>The signer that adds a signature to each attempt at the origin that the route names.
RequestSigner states when the fetcher calls the signer. The headers
of the signer replace the headers of the same name in each layer: the
fetcher and the request. A redirect hop at another origin gets no
signature. The default is None.
The signer is a credential. Fetcher::new refuses it beside
basic_auth, beside
bearer_token, and beside an
Authorization entry in headers, because
a signature can set the same header. For the same reason, a fetch or an
upload with a credential of its own fails before admission: basic-auth
credentials, a bearer token, or an Authorization request header.
Each mirror must be https, unless
allow_cleartext_credentials
is true.
allow_cleartext_credentials: boolThe permission for a credential to reach a cleartext origin.
If this is true, Fetcher::new does not refuse a cleartext mirror
beside a credential: basic_auth,
bearer_token,
signer, or a credential header in
headers. A fetch or an upload also does
not refuse a credential for a cleartext destination, whatever the flag
of the request is. FetchRequest::allow_cleartext_credentials states
that rule.
The redirect rules apply with this flag. A hop at another origin gets no
credential and no signature, and a hop from https to http is
refused. The default is false.
A caller sets it for a server on a loopback address, or for a server behind a proxy that terminates TLS.
tls: TlsOptionsThe trust anchors and the client certificate for https mirrors.
The default is TlsOptions::default: TrustRoots::System and no
client identity.
proxy: ProxyThe proxy through which the fetcher reaches an origin.
Fetcher::new resolves the value once, and a request does not read it
again. It refuses a proxy URL that is not http://host[:port],
socks5://host[:port], or socks5h://host[:port], a SOCKS5 URL with a
userinfo that SOCKS proxies refuses, and a proxy variable with
white space around its value.
The default is Proxy::Environment, the proxy that the process
environment names.
http2: boolThe switch that offers HTTP/2 in ALPN.
If this is false, the fetcher uses HTTP/1.1, also with a server that
supports HTTP/2. The default is true.
max_retries: u32The number of times that a fetch repeats a round after a retryable failure.
Fetcher::fetch states the retry rules. The default is 5.
max_redirects: u32The number of redirects that one attempt against one destination follows.
The attempt follows a 301, 302, 303, 307, or 308 while it followed fewer
redirects than this value. If the next one names a URL, the attempt fails
definitively with Error::RedirectLimit. If it names no URL, the
attempt reports its own status.
Zero follows nothing, so each of those statuses is then a definitive
answer. A fetch with FetchRequest::max_error_body then gets the
headers of the redirect, Location included, in its
Error::HttpStatus. The count belongs to one attempt, so a repeated
round counts again from the destination that the route names.
Fetcher::fetch states the redirect rules. The default is 10.
max_outstanding: usizeThe number of requests in flight at one time.
The fetcher admits this many requests at a time, and serves the queue in
Priority order. A request holds its permit until the fetch fails, or
until its response body reaches its end or is dropped. A body in flight
occupies a connection, so it keeps the permit.
The default is 8. The fetcher admits at least one request, so 0 admits one request.
connect_timeout: DurationThe time limit to open a connection.
The limit applies to the TCP connect, the TLS handshake, and the HTTP
handshake together. Through a proxy, it also applies to the connect to
the proxy and to the CONNECT exchange.
The TCP connect resolves the host name, then races the addresses that the resolver gave. A new attempt starts every 250ms, and an attempt that fails starts the next one immediately. So the limit includes the resolution and all attempts.
The expiry is a transport failure. So it is retryable, and the fetch tries the next destination. The default is 30 s.
progress_timeout: DurationThe longest time that a response can go without bytes.
The window applies to the wait for the response head and to each stall of the body. It measures the silence since a read asked for bytes. So it limits silence, and leaves the transfer time unlimited.
The window runs from the read that finds no bytes until bytes arrive. After a read found no bytes, the window runs also when no read is outstanding. A body that no read found empty is not on the clock.
If the body stalls, the read fails with
io::ErrorKind::TimedOut, and each
later read fails the same way. An expired wait for the head is a
retryable transport failure, so the fetch tries the next destination.
The default is 60 s.
low_speed: Option<LowSpeed>The lowest transfer rate that an attempt accepts, as LowSpeed
states.
The response head must arrive within time of the start of the attempt,
rounded up to whole seconds, redirects included. The rate of the body
counts from its first read. So the fetcher does not measure a body that
waits for its consumer before the consumer asks for bytes.
The fetcher samples the body only while a read is outstanding. A gap between reads that is longer than a second counts as one second. The bytes that arrived in the gap count at the next read.
A transfer slower than the rate is a transport failure. A slow head is a
retryable failure of the attempt. A slow body fails the read with
io::ErrorKind::TimedOut.
None checks no rate. The default is None.
fetch_timeout: Option<Duration>The longest time that one fetch can take to get a response head.
The limit includes all rounds, all retries, and the delays between them,
from the admission of the fetch until the response head arrives. Only
progress_timeout limits the body
that follows. None sets no limit. The default is 300 s.
This limit is the longest time that a fetch with no response holds an
admission permit. So a caller sizes it against
max_outstanding. Without this
limit, an unresponsive peer can stall a fetch for a product of three
values. These are the destination count, the retry count, and the two
deadlines of an attempt.
On expiry, the fetch fails with Error::Fetch and tries nothing more.
The attempt that the expiry cancels releases the admission permit. An
upload has a narrower limit, which Fetcher::upload states.
Implementations§
Source§impl FetcherOptions
impl FetcherOptions
Sourcepub fn new(url: impl Into<String>) -> FetcherOptions
pub fn new(url: impl Into<String>) -> FetcherOptions
Creates options with one base URL and the default of each other field.