Skip to main content

Proxy

Enum Proxy 

Source
pub enum Proxy {
    None,
    Environment,
    Variables(Vec<(String, String)>),
    Url(String),
}
Expand description

The proxy through which a Fetcher reaches each origin.

Fetcher::new resolves each form once, and refuses a proxy URL that the fetcher cannot connect through. A request does not read the environment again.

The Debug output does not show the userinfo of a proxy URL. So the log of a struct that holds proxy credentials does not show them.

§Variables

http_proxy serves http origins, and https_proxy serves https origins. If the variable of the scheme is unset, all_proxy serves the origin. The fetcher also reads each name in upper case, except HTTP_PROXY. A CGI gateway gives a request header Proxy to the program as HTTP_PROXY, so a client can set that variable with a request.

The lower-case name has priority over the upper-case name. An empty value counts as unset.

§White space

If the value of http_proxy, https_proxy, or all_proxy, or of an upper-case name, has white space at its start or end, Fetcher::new fails with Error::Unsupported. A value of white space alone also fails. It is not empty, so it counts as set and hides the upper-case name.

The fetcher checks the value of each variable that the lookup reads, when it builds the fetcher. It checks a variable also if no request goes through that proxy. The message names the variable and holds no part of the value, which can hold a password. The fetcher trims the URL of Proxy::Url and each no_proxy entry.

§Proxy URL

A proxy URL has the form http://host[:port], and the port is 80 by default. The URL has no path other than /, no query, and no fragment. The fetcher percent-decodes the userinfo and sends it to the proxy as Proxy-Authorization: Basic.

Any other form fails Fetcher::new with Error::Unsupported, for example an https:// or a socks5:// proxy. This applies to a URL from the options and to a URL from the environment. The message names the value without its userinfo.

§Exemptions

no_proxy is a comma-separated list of the origins that the two environment forms exempt. An entry holds a host text, with one leading . if it is written with one, and :port if it names a port. The fetcher ignores the space around an entry. An entry that names no host exempts nothing, for example an empty entry, ., or :8080.

If the port text of an entry is not a number from 0 to 65535, the whole entry is one host text. No origin holds that text, so the entry exempts nothing.

* as a whole entry exempts all hosts. It is the one wildcard that the list reads. *.example.com is a host text, and no origin holds it.

An entry matches an origin if it equals the host, or if the host ends with a . and the entry. The fetcher removes one leading . from the entry first, so .example.com and example.com both exempt a.example.com. A second leading . is part of the host text of the entry. An entry with :port matches that port alone.

The match compares the host text of the URL, with ASCII case ignored. It never compares the address of the host. So localhost exempts no origin written as 127.0.0.1, and an entry that is an IP literal matches that text alone.

An entry in CIDR notation names no network. The fetcher reads it as a host text, which no origin holds. This is a divergence from curl 7.86 and later, which read such an entry as a network. An empty no_proxy value exempts nothing, and Proxy::Url reads no exemptions.

§Cleartext origins

The fetcher reaches a cleartext origin behind a proxy over a connection to the proxy. The request carries the absolute-form target, the whole http://host/path URL, and the Host header of the origin. Such a connection uses HTTP/1.1, because cleartext HTTP/2 needs prior knowledge or an upgrade.

The pool keeps such a connection under the proxy endpoint, so one proxy connection carries requests for all cleartext origins. The pool key marks a connection as a proxy connection. So the pool never gives a direct connection to the proxy endpoint to a proxied request, or the reverse. The two request forms differ, and a server answers the unexpected form with a 404.

§TLS origins

The fetcher reaches a TLS origin behind a proxy over a CONNECT tunnel. The request names the target as host:port. The port is always written, and an IPv6 literal keeps its brackets. If the proxy URL holds userinfo, the CONNECT carries the same Proxy-Authorization.

On a 2xx answer, the fetcher gets the tunneled socket back. The TLS handshake, the ALPN selection, and the pool entry are then the same as for a direct connection to that origin. Nothing follows a CONNECT response, so a byte that arrives before the client sends fails the connect.

A non-2xx answer is a retryable failure, and a 407 is a definitive failure. Both are Error::Fetch and name the proxy. connect_timeout is the limit for all these steps together: the connect to the proxy, the CONNECT exchange, the TLS handshake, and the HTTP handshake.

§Proxy credential

The proxy credential belongs to the connection layer. It goes to the proxy on a proxied cleartext request and on a CONNECT, and to no origin. It is not in the merged header list, so the cleartext credential check and the redirect scoping do not read it. A tunnel carries no part of it.

A Proxy-Authorization header that a caller sets keeps the meaning that it has without a proxy. It is a credential in the merged list. A fetch refuses it for a cleartext destination, as it refuses an Authorization or a Cookie header.

On a proxied cleartext request, the header of the caller replaces the proxy credential of the fetcher. Two values for one header give two answers to one question. Over a tunnel, the two never meet. The header of the caller goes to the origin, and the credential of the fetcher goes to the proxy.

§Redirects

The fetcher makes the proxy decision for each hop, from the origin of that hop. So a redirect to another origin goes the same way as a route that names that origin. A proxy does not change the cleartext rule: a cleartext origin is cleartext also through a proxy.

§Examples

use ostrya_fetch::{Fetcher, FetcherOptions, Proxy};
let mut options = FetcherOptions::new("https://example.com/repo");
options.proxy = Proxy::Variables(vec![
    ("https_proxy".into(), "http://proxy.example.com:3128".into()),
    ("no_proxy".into(), ".internal.example.com".into()),
]);
let fetcher = Fetcher::new(options).await?;

Variants§

§

None

A direct connection, whatever the environment holds.

§

Environment

The proxy variables of the process environment.

Fetcher::new reads the variables once. This is the default. Variables states the names, and White space states the check of each value.

§

Variables(Vec<(String, String)>)

The proxy variables, given as name and value pairs.

The fetcher does not read the process environment. It ignores a name that the environment forms do not read. Of two entries of one name, the first entry with a value counts. White space states the check of each value.

§

Url(String)

One http:// proxy URL for all origins.

The fetcher sends the userinfo of the URL as Proxy-Authorization: Basic. No origin is exempt, because the fetcher reads the environment for neither the proxy nor the exemptions. The fetcher trims white space around the URL.

Trait Implementations§

Source§

impl Clone for Proxy

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 Proxy

Source§

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

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

impl Default for Proxy

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for Proxy

§

impl RefUnwindSafe for Proxy

§

impl Send for Proxy

§

impl Sync for Proxy

§

impl Unpin for Proxy

§

impl UnsafeUnpin for Proxy

§

impl UnwindSafe for Proxy

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