#[non_exhaustive]pub struct ProxyEndpoint {
pub scheme_hint: Option<ProxyScheme>,
pub host: Host,
pub port: u16,
pub auth: Option<ProxyAuth>,
}Expand description
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.scheme_hint: Option<ProxyScheme>Wire protocol hint when the source named one.
host: HostProxy host.
port: u16Proxy port.
auth: Option<ProxyAuth>Embedded credentials, if any.
Implementations§
Source§impl ProxyEndpoint
impl ProxyEndpoint
Sourcepub fn new(host: Host, port: u16) -> Self
pub fn new(host: Host, port: u16) -> Self
Build an endpoint from an already-parsed host and port.
Sourcepub fn with_scheme_hint(self, scheme: ProxyScheme) -> Self
pub fn with_scheme_hint(self, scheme: ProxyScheme) -> Self
Set the scheme hint (builder style).
Sourcepub fn parse(input: &str, default_port: u16) -> Result<Self, Error>
pub fn parse(input: &str, default_port: u16) -> Result<Self, Error>
Parse a proxy address in any of the shapes operating systems store.
host, host:port, [::1]:8080, user:pass@host[:port], or any of those behind
a scheme://. Credentials do not need the scheme: the userinfo split happens after
the optional prefix, so a bare user:pass@host carries a secret just as a
scheme:// one does. The last @ is the delimiter, as in WHATWG’s authority
state, so user@corp.example:pw@proxy:8080 keeps an email address as the user name.
Port: explicit, else scheme default, else default_port.
A path, query or fragment is dropped, so http://proxy:8080/ and
http://proxy:8080 are the same endpoint; nothing after the authority survives.
One holding an @ is refused with Error::InvalidProxyServer: the host in front
of it is then the start of a password that held a /, ? or #.
let ep = ProxyEndpoint::parse("socks5://[::1]", 80).unwrap();
assert_eq!(ep.scheme_hint, Some(ProxyScheme::Socks5));
assert_eq!(ep.port, 1080);
assert_eq!(ep.authority(), "[::1]:1080");§Errors
Error::InvalidProxyServer if the input is not a usable address, or
Error::UnsupportedProxyScheme for a scheme:// prefix this crate does not
model. Never Error::InvalidProxyUrl: that one belongs to the callers that
parse an AutoConfigURL-style value, not to an address.
U+FFFD anywhere in the authority (credentials included) is one of the unusable addresses. It is what a lossy byte-to-text conversion leaves behind, and this crate’s platform readers convert that way so that a value they could not decode is refused here instead of reading as unset. A path or query is dropped before the check, so the character is only refused where the answer is built from it.
The host:port form, with IPv6 hosts re-bracketed.