pub struct LoopbackUrl { /* private fields */ }Expand description
A plain-HTTP URL whose host is a loopback literal, kept in canonical form.
Step 1 has no TLS, so the client refuses to talk to anything but the
local machine. The accepted hosts are exactly those the node accepts in
its Host header: any IPv4 address in 127.0.0.0/8 written in
canonical dotted-decimal form (four decimal octets, no leading zeros, so
127.0.0.2 but not 127.1 or 127.000.0.1), [::1] and localhost
(lowercase). localhost is never looked up: requests to it are
connected to 127.0.0.1 while Host and the signed URL keep
localhost (see connect_host).
The port is always explicit in the canonical form (80 when omitted),
because the node rebuilds the URL it verifies signatures against as
http://<Host header><path> and the client sends Host: <host>:<port>.
A path is kept when present. Commands that talk to the API need a bare
origin (is_origin); stratum sign-challenge uses the
path as the exact claim URL. User information, queries, fragments,
percent signs, whitespace and other non-printable characters are refused.
§Examples
use stratum_node_cli::LoopbackUrl;
let url: LoopbackUrl = "http://localhost:7460/".parse()?;
assert_eq!(url.authority(), "localhost:7460");
assert!(url.is_origin());
assert_eq!(url.join("/readyz"), "http://localhost:7460/readyz");
assert!("http://127.0.0.2:7460".parse::<LoopbackUrl>().is_ok());
assert!("http://192.0.2.1:7460".parse::<LoopbackUrl>().is_err());
assert!("https://127.0.0.1:7460".parse::<LoopbackUrl>().is_err());Implementations§
Source§impl LoopbackUrl
impl LoopbackUrl
Sourcepub fn host(&self) -> &str
pub fn host(&self) -> &str
Returns the host literal: an address in 127.0.0.0/8, [::1] or
localhost.
Sourcepub fn connect_host(&self) -> &str
pub fn connect_host(&self) -> &str
Returns the address literal the client connects to: the host itself,
except that localhost becomes 127.0.0.1.
localhost is not resolved, so neither /etc/hosts nor any
resolver can send a request (or the bootstrap token) off the
machine. Host and the signed URL still name localhost. A node
listening only on [::1] must be addressed as [::1].
§Examples
use stratum_node_cli::LoopbackUrl;
let url: LoopbackUrl = "http://localhost:7460".parse()?;
assert_eq!(url.connect_host(), "127.0.0.1");
assert_eq!(url.authority(), "localhost:7460");Returns <host>:<port>, the value the client sends as Host.
Sourcepub fn join(&self, path: &str) -> String
pub fn join(&self, path: &str) -> String
Returns http://<host>:<port> followed by path, ignoring any path
this URL carries. path should start with /.
Sourcepub fn to_url_string(&self) -> String
pub fn to_url_string(&self) -> String
Returns this URL in canonical form, path included.
Trait Implementations§
Source§impl Clone for LoopbackUrl
impl Clone for LoopbackUrl
Source§impl Debug for LoopbackUrl
impl Debug for LoopbackUrl
Source§impl Display for LoopbackUrl
impl Display for LoopbackUrl
impl Eq for LoopbackUrl
Source§impl FromStr for LoopbackUrl
impl FromStr for LoopbackUrl
Source§impl Hash for LoopbackUrl
impl Hash for LoopbackUrl
Source§impl PartialEq for LoopbackUrl
impl PartialEq for LoopbackUrl
impl StructuralPartialEq for LoopbackUrl
Auto Trait Implementations§
impl Forget for LoopbackUrl
impl Freeze for LoopbackUrl
impl Move for LoopbackUrl
impl RefUnwindSafe for LoopbackUrl
impl Send for LoopbackUrlwhere
RawVecInner: Send,
impl Sync for LoopbackUrlwhere
RawVecInner: Sync,
impl Unpin for LoopbackUrl
impl UnsafeUnpin for LoopbackUrl
impl UnwindSafe for LoopbackUrlwhere
RawVecInner: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.