Enum Host
#[non_exhaustive]pub enum Host {
Name(Domain),
Address(IpAddr),
Uninterpreted(UninterpretedHost),
}net only.Expand description
Either a Domain, an IpAddr, or UninterpretedHost bytes
preserved verbatim from a URI authority.
Uninterpreted covers the RFC 3986 host shapes that aren’t a strict
DNS-label-shaped Domain or a recognized IP address — pct-encoded
reg-name (exa%6Dple.com), sub-delim hostnames (tag,with,commas),
IPvFuture literals ([vN.X]), and raw UTF-8 host bytes preserved
under graceful URI / IRI parsing. The variant exists so a proxy
receiving wire bytes can forward them faithfully; callers needing a
canonical typed form convert via the TryFrom impls on
UninterpretedHost.
Equality, hashing, and ordering bridge across variant boundaries per
RFC 3986 §6.2.2.2: see HostRef’s type-level docs.
§Empty Uninterpreted host
RFC 3986 §3.2.2 reg-name = *(...) permits empty bytes, so URIs like
file:///path or unix:///run/x parse with Host::Uninterpreted(b"").
This is URI-valid but not network-valid — protocol writers that
have no representation for “no host” (SOCKS5, TLS SNI, HTTP Host:)
will refuse it. Code dispatching a Host onto a network call must
either reject the empty case or substitute a sensible default.
§Alternate IPv4 forms (SSRF awareness)
Inputs that look like IP addresses but aren’t accepted by Rust’s
Ipv4Addr::from_str — octal (0177.0.0.1), hex (0x7f.0.0.1),
3-part (127.0.1), and integer (2130706433) — parse as
Host::Name(Domain) rather than
Host::Address, because each label is digit-only
and passes the DNS-label byte set. This is RFC 3986 compliant (the
strings are reg-names under §3.2.2) but diverges from
browsers, which normalise all four to 127.0.0.1.
SSRF caveat: code that filters destination addresses on
Host::Address will see 0177.0.0.1 as a Name and bypass
IP-based allowlists / blocklists. Either:
- resolve through DNS (loopback returns naturally) before applying the filter, OR
- reject any
Namewhose labels look digit-only at the policy layer, OR - call
crate::uri::Uri::canonicalizefirst — it doesn’t promote these toAddress(Rust’s strict parser still rejects), so this is informational rather than a fix.
§Why #[non_exhaustive]
Variant matching is a footgun on this type: a Domain can live
in Name or in Uninterpreted (pct-encoded bytes that decode
to a domain), and an IpAddr can live in Address or in
Uninterpreted (pct-encoded dotted-quad). External callers that
pattern-match on the variant tag will miss the bridged forms.
Use try_as_domain /
try_as_ip (and the try_into_* consuming
counterparts) which bridge across variants.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Name(Domain)
A DNS-label-shaped name (ASCII, IDN normalised to ACE on
construction via Domain::try_from).
Address(IpAddr)
A literal IPv4 or IPv6 address.
Uninterpreted(UninterpretedHost)
Host bytes preserved verbatim. See UninterpretedHost.
Implementations§
§impl Host
impl Host
pub fn try_as_domain(
&self,
) -> Result<Cow<'_, Domain>, Box<dyn Error + Send + Sync>>
pub fn try_as_domain( &self, ) -> Result<Cow<'_, Domain>, Box<dyn Error + Send + Sync>>
Returns true if this is the Host::Name variant.
View as a Domain, bridging the Uninterpreted variant.
Cow::Borrowed for Name; Cow::Owned for an Uninterpreted
whose pct-decoded (and IDN-normalized) bytes parse as a domain.
Address and IPvFuture-bracketed Uninterpreted fail.
pub fn try_into_domain(self) -> Result<Domain, Box<dyn Error + Send + Sync>>
pub fn try_into_domain(self) -> Result<Domain, Box<dyn Error + Send + Sync>>
Consuming form of try_as_domain.
pub fn try_as_ip(&self) -> Result<IpAddr, Box<dyn Error + Send + Sync>>
pub fn try_as_ip(&self) -> Result<IpAddr, Box<dyn Error + Send + Sync>>
View as an IpAddr, bridging the Uninterpreted variant.
Returns the address from Address directly; Uninterpreted
succeeds when its pct-decoded bytes parse as an IPv4 or IPv6
address. Name and IPvFuture-bracketed Uninterpreted fail.
pub fn view(&self) -> HostRef<'_>
pub fn view(&self) -> HostRef<'_>
Borrowed view. Same shape as From<&Self> for HostRef but
surfaces the borrowed view as an inherent method so call sites
don’t need the trait in scope.
pub fn to_str(&self) -> Cow<'_, str>
pub fn to_str(&self) -> Cow<'_, str>
Returns this host as a string. See HostRef::to_str for the
borrow / allocation behavior.
pub fn as_unicode(&self) -> Cow<'_, str>
Available on crate feature idna only.
pub fn as_unicode(&self) -> Cow<'_, str>
idna only.Returns the Unicode (display) form of this host. For named hosts,
any xn-- A-labels are inverse-encoded via UTS #46. IP addresses
are rendered to their standard textual form.
Cow::Borrowed when no conversion is needed; Cow::Owned for
IP addresses and IDN A-labels that actually require decoding.
§impl Host
impl Host
pub const LOCALHOST_IPV4: Host
pub const LOCALHOST_IPV4: Host
Local loopback address (IPv4)
pub const LOCALHOST_IPV6: Host
pub const LOCALHOST_IPV6: Host
Local loopback address (IPv6)
pub const LOCALHOST_NAME: Host
pub const LOCALHOST_NAME: Host
Local loopback name
pub const DEFAULT_IPV4: Host
pub const DEFAULT_IPV4: Host
Default address, not routable
pub const DEFAULT_IPV6: Host
pub const DEFAULT_IPV6: Host
Default address, not routable (IPv6)
pub const BROADCAST_IPV4: Host
pub const BROADCAST_IPV4: Host
Broadcast address (IPv4)
pub const EXAMPLE_NAME: Host
pub const EXAMPLE_NAME: Host
example.com domain name
pub const fn from_static(s: &'static str) -> Host
pub const fn from_static(s: &'static str) -> Host
Compile-time constructor for a Domain-shaped host. Panics
at compile time when s isn’t a valid domain.
Trait Implementations§
§impl<'de> Deserialize<'de> for Host
impl<'de> Deserialize<'de> for Host
§fn deserialize<D>(
deserializer: D,
) -> Result<Host, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Host, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
§impl DomainLabels for Host
impl DomainLabels for Host
§type LabelIter<'a> = HostLabelIter<'a>
type LabelIter<'a> = HostLabelIter<'a>
self, yielded most-specific-first
("www.example.com".labels() yields www, example, com).§fn labels(&self) -> <Host as DomainLabels>::LabelIter<'_>
fn labels(&self) -> <Host as DomainLabels>::LabelIter<'_>
self.§fn label_count(&self) -> usize
fn label_count(&self) -> usize
§fn starts_with<D>(&self, prefix: &D) -> boolwhere
D: DomainLabels + ?Sized,
fn starts_with<D>(&self, prefix: &D) -> boolwhere
D: DomainLabels + ?Sized,
§fn is_subdomain_of<D>(&self, parent: &D) -> boolwhere
D: DomainLabels + ?Sized,
fn is_subdomain_of<D>(&self, parent: &D) -> boolwhere
D: DomainLabels + ?Sized,
§fn parent(&self) -> Option<Domain>
fn parent(&self) -> Option<Domain>
Domain (everything but the leftmost label), or
None if self has fewer than two labels.§fn suffix_iter(&self) -> SuffixIter<'_, Self> ⓘwhere
Self: Sized,
fn suffix_iter(&self) -> SuffixIter<'_, Self> ⓘwhere
Self: Sized,
self and each successive parent, ending just before the
empty domain. For "a.b.c" yields "a.b.c", "b.c", "c".§impl From<Host> for ForwardedAuthority
impl From<Host> for ForwardedAuthority
§fn from(value: Host) -> ForwardedAuthority
fn from(value: Host) -> ForwardedAuthority
§impl From<Host> for HostWithOptPort
impl From<Host> for HostWithOptPort
§fn from(host: Host) -> HostWithOptPort
fn from(host: Host) -> HostWithOptPort
§impl From<HostWithOptPort> for Host
impl From<HostWithOptPort> for Host
§fn from(hwop: HostWithOptPort) -> Host
fn from(hwop: HostWithOptPort) -> Host
§impl From<HostWithPort> for Host
impl From<HostWithPort> for Host
§fn from(hwp: HostWithPort) -> Host
fn from(hwp: HostWithPort) -> Host
§impl IntoCanonicalIpAddr for Host
impl IntoCanonicalIpAddr for Host
fn into_canonical_ip_addr(self) -> Host
§impl Ord for Host
impl Ord for Host
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
§impl PartialEq<str> for Host
impl PartialEq<str> for Host
§impl PartialOrd for Host
impl PartialOrd for Host
§impl<'a> RamaTryFrom<&'a Host, RamaTlsRustlsCrateMarker> for ServerName<'a>
impl<'a> RamaTryFrom<&'a Host, RamaTlsRustlsCrateMarker> for ServerName<'a>
type Error = Box<dyn Error + Send + Sync>
fn rama_try_from( value: &'a Host, ) -> Result<ServerName<'a>, <ServerName<'a> as RamaTryFrom<&'a Host, RamaTlsRustlsCrateMarker>>::Error>
§impl<'a> RamaTryFrom<&ServerName<'a>, RamaTlsRustlsCrateMarker> for Host
impl<'a> RamaTryFrom<&ServerName<'a>, RamaTlsRustlsCrateMarker> for Host
type Error = Box<dyn Error + Send + Sync>
fn rama_try_from( value: &ServerName<'a>, ) -> Result<Host, <Host as RamaTryFrom<&ServerName<'a>, RamaTlsRustlsCrateMarker>>::Error>
§impl RamaTryFrom<Host, RamaTlsRustlsCrateMarker> for ServerName<'_>
impl RamaTryFrom<Host, RamaTlsRustlsCrateMarker> for ServerName<'_>
type Error = Box<dyn Error + Send + Sync>
fn rama_try_from( value: Host, ) -> Result<ServerName<'_>, <ServerName<'_> as RamaTryFrom<Host, RamaTlsRustlsCrateMarker>>::Error>
§impl<'a> RamaTryFrom<ServerName<'a>, RamaTlsRustlsCrateMarker> for Host
impl<'a> RamaTryFrom<ServerName<'a>, RamaTlsRustlsCrateMarker> for Host
type Error = Box<dyn Error + Send + Sync>
fn rama_try_from( value: ServerName<'a>, ) -> Result<Host, <Host as RamaTryFrom<ServerName<'a>, RamaTlsRustlsCrateMarker>>::Error>
§impl Serialize for Host
impl Serialize for Host
§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
§impl TraceField for Host
impl TraceField for Host
fn field_type() -> FieldType
§fn encode<W>(&self, enc: &mut EventEncoder<'_, W>) -> Result<(), Error>where
W: Write,
fn encode<W>(&self, enc: &mut EventEncoder<'_, W>) -> Result<(), Error>where
W: Write,
§fn decode_ref<'a>(
val: &FieldValueRef<'a>,
) -> Option<<Host as TraceField>::Ref<'a>>
fn decode_ref<'a>( val: &FieldValueRef<'a>, ) -> Option<<Host as TraceField>::Ref<'a>>
§fn is_optional() -> bool
fn is_optional() -> bool
§fn decode_missing<'a>() -> Option<Self::Ref<'a>>
fn decode_missing<'a>() -> Option<Self::Ref<'a>>
None for required fields (decode failure) and Some(None) for
optional fields.§impl TryFrom<&HeaderValue> for Host
Available on crate feature http only.
impl TryFrom<&HeaderValue> for Host
http only.§impl TryFrom<HeaderValue> for Host
Available on crate feature http only.
impl TryFrom<HeaderValue> for Host
http only.impl Eq for Host
Auto Trait Implementations§
impl !Freeze for Host
impl RefUnwindSafe for Host
impl Send for Host
impl Sync for Host
impl Unpin for Host
impl UnsafeUnpin for Host
impl UnwindSafe for Host
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more§impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
fn rama_try_from(value: T) -> Result<U, <U as RamaTryFrom<T>>::Error>
§impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
type Error = <U as RamaTryFrom<T, CrateMarker>>::Error
fn rama_try_into(self) -> Result<U, <U as RamaTryFrom<T, CrateMarker>>::Error>
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.
§impl<V, F> ValueFormatter<&V> for F
impl<V, F> ValueFormatter<&V> for F
§fn format_value(writer: impl ValueWriter, value: &&V)
fn format_value(writer: impl ValueWriter, value: &&V)
value to writer§impl<V, F> ValueFormatter<Arc<V>> for F
impl<V, F> ValueFormatter<Arc<V>> for F
§fn format_value(writer: impl ValueWriter, value: &Arc<V>)
fn format_value(writer: impl ValueWriter, value: &Arc<V>)
value to writer§impl<V, F> ValueFormatter<Box<V>> for F
impl<V, F> ValueFormatter<Box<V>> for F
§fn format_value(writer: impl ValueWriter, value: &Box<V>)
fn format_value(writer: impl ValueWriter, value: &Box<V>)
value to writer§impl<V, F> ValueFormatter<Cow<'_, V>> for F
impl<V, F> ValueFormatter<Cow<'_, V>> for F
§fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
value to writer§impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
§fn format_value(writer: impl ValueWriter, value: &Option<V>)
fn format_value(writer: impl ValueWriter, value: &Option<V>)
value to writer