Skip to main content

LoopbackUrl

Struct LoopbackUrl 

Source
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

Source

pub fn host(&self) -> &str

Returns the host literal: an address in 127.0.0.0/8, [::1] or localhost.

Source

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");
Source

pub fn port(&self) -> u16

Returns the port, 80 when the URL named none.

Source

pub fn authority(&self) -> String

Returns <host>:<port>, the value the client sends as Host.

Source

pub fn path(&self) -> &str

Returns the path, empty for a bare origin. A lone / is dropped.

Source

pub fn is_origin(&self) -> bool

Returns true when the URL has no path beyond an optional /.

Source

pub fn join(&self, path: &str) -> String

Returns http://<host>:<port> followed by path, ignoring any path this URL carries. path should start with /.

Source

pub fn to_url_string(&self) -> String

Returns this URL in canonical form, path included.

Trait Implementations§

Source§

impl Clone for LoopbackUrl

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 LoopbackUrl

Source§

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

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

impl Display for LoopbackUrl

Source§

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

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

impl Eq for LoopbackUrl

Source§

impl FromStr for LoopbackUrl

Source§

fn from_str(text: &str) -> Result<Self, Self::Err>

Parses http://<loopback host>[:<port>][<path>].

Source§

type Err = ParseUrlError

The associated error which can be returned from parsing.
Source§

impl Hash for LoopbackUrl

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for LoopbackUrl

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LoopbackUrl

Auto Trait Implementations§

§

impl Forget for LoopbackUrl

§

impl Freeze for LoopbackUrl
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl Move for LoopbackUrl

§

impl RefUnwindSafe for LoopbackUrl

§

impl Send for LoopbackUrl
where RawVecInner: Send,

§

impl Sync for LoopbackUrl
where RawVecInner: Sync,

§

impl Unpin for LoopbackUrl
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for LoopbackUrl

§

impl UnwindSafe for LoopbackUrl
where RawVecInner: UnwindSafe,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V