pub struct HttpUri { /* private fields */ }Expand description
A O(1) clonable struct for representing http uri.
Implementations§
Source§impl HttpUri
impl HttpUri
Get authority components of http uri
Get authority str of this http uri
Sourcepub fn is_rfc3986_normalized(&self) -> bool
pub fn is_rfc3986_normalized(&self) -> bool
Checks if uri is std normalized as per rfc3986
Sourcepub fn normalize_rfc3986(&self) -> HttpUri
pub fn normalize_rfc3986(&self) -> HttpUri
Returns a std normal http uri. standard normalization follows rfc 3986
Sourcepub fn is_http_normalized(&self) -> bool
pub fn is_http_normalized(&self) -> bool
Checks if uri is http normalized.
Sourcepub fn http_normalized(&self) -> HttpUri
pub fn http_normalized(&self) -> HttpUri
Returns a normal http uri. This function performs additional http specific normalization along with uri normalization specified by rfc3986.
Http normalization entails:
- Normalization of port, If default port is explicitly specified,it will be removed.
- Normalization of path: Empty path will be normalized to
/. - If there are non-trailing empty segments in path, they will be removed.
Sourcepub fn is_localhost(&self) -> bool
pub fn is_localhost(&self) -> bool
Get if http uri’s host is localhost.
Methods from Deref<Target = UriStr>§
Sourcepub fn to_absolute_and_fragment(
&self,
) -> (&RiAbsoluteStr<S>, Option<&RiFragmentStr<S>>)
pub fn to_absolute_and_fragment( &self, ) -> (&RiAbsoluteStr<S>, Option<&RiFragmentStr<S>>)
Splits the IRI into an absolute IRI part and a fragment part.
A leading # character is truncated if the fragment part exists.
§Examples
If the IRI has a fragment part, Some(_) is returned.
let iri = IriStr::new("foo://bar/baz?qux=quux#corge")?;
let (absolute, fragment) = iri.to_absolute_and_fragment();
let fragment_expected = IriFragmentStr::new("corge")?;
assert_eq!(absolute, "foo://bar/baz?qux=quux");
assert_eq!(fragment, Some(fragment_expected));When the fragment part exists but is empty string, Some(_) is returned.
let iri = IriStr::new("foo://bar/baz?qux=quux#")?;
let (absolute, fragment) = iri.to_absolute_and_fragment();
let fragment_expected = IriFragmentStr::new("")?;
assert_eq!(absolute, "foo://bar/baz?qux=quux");
assert_eq!(fragment, Some(fragment_expected));If the IRI has no fragment, None is returned.
let iri = IriStr::new("foo://bar/baz?qux=quux")?;
let (absolute, fragment) = iri.to_absolute_and_fragment();
assert_eq!(absolute, "foo://bar/baz?qux=quux");
assert_eq!(fragment, None);Sourcepub fn to_absolute(&self) -> &RiAbsoluteStr<S>
pub fn to_absolute(&self) -> &RiAbsoluteStr<S>
Strips the fragment part if exists, and returns &RiAbsoluteStr.
§Examples
let iri = IriStr::new("foo://bar/baz?qux=quux#corge")?;
assert_eq!(iri.to_absolute(), "foo://bar/baz?qux=quux");let iri = IriStr::new("foo://bar/baz?qux=quux")?;
assert_eq!(iri.to_absolute(), "foo://bar/baz?qux=quux");Sourcepub fn ensure_rfc3986_normalizable(&self) -> Result<(), Error>
pub fn ensure_rfc3986_normalizable(&self) -> Result<(), Error>
Returns Ok(()) if the IRI is normalizable by the RFC 3986 algorithm.
§Examples
use iri_string::types::IriStr;
let iri = IriStr::new("HTTP://example.COM/foo/%2e/bar/..")?;
assert!(iri.ensure_rfc3986_normalizable().is_ok());
let iri2 = IriStr::new("scheme:/..//bar")?;
// The normalization result would be `scheme://bar` according to RFC
// 3986, but it is unintended and should be treated as a failure.
// This crate automatically handles this case so that `.normalize()` won't fail.
assert!(!iri.ensure_rfc3986_normalizable().is_err());Sourcepub fn is_normalized(&self) -> bool
pub fn is_normalized(&self) -> bool
Returns true if the IRI is already normalized.
This returns the same result as self.normalize().to_string() == self,
but does this more efficiently without heap allocation.
§Examples
use iri_string::format::ToDedicatedString;
use iri_string::types::IriStr;
let iri = IriStr::new("HTTP://example.COM/foo/./bar/%2e%2e/../baz?query#fragment")?;
assert!(!iri.is_normalized());
let normalized = iri.normalize().to_dedicated_string();
assert_eq!(normalized, "http://example.com/baz?query#fragment");
assert!(normalized.is_normalized());use iri_string::format::ToDedicatedString;
use iri_string::types::IriStr;
let iri = IriStr::new("scheme:/.///foo")?;
// Already normalized.
assert!(iri.is_normalized());use iri_string::format::ToDedicatedString;
use iri_string::types::IriStr;
let iri = IriStr::new("scheme:relative/..//not-a-host")?;
// Default normalization algorithm assumes the path part to be NOT opaque.
assert!(!iri.is_normalized());
let normalized = iri.normalize().to_dedicated_string();
assert_eq!(normalized, "scheme:/.//not-a-host");Sourcepub fn is_normalized_rfc3986(&self) -> bool
pub fn is_normalized_rfc3986(&self) -> bool
Returns true if the IRI is already normalized in the sense of RFC 3986.
This returns the same result as
self.ensure_rfc3986_normalizable() && (self.normalize().to_string() == self),
but does this more efficiently without heap allocation.
§Examples
use iri_string::format::ToDedicatedString;
use iri_string::types::IriStr;
let iri = IriStr::new("HTTP://example.COM/foo/./bar/%2e%2e/../baz?query#fragment")?;
assert!(!iri.is_normalized_rfc3986());
let normalized = iri.normalize().to_dedicated_string();
assert_eq!(normalized, "http://example.com/baz?query#fragment");
assert!(normalized.is_normalized_rfc3986());use iri_string::format::ToDedicatedString;
use iri_string::types::IriStr;
let iri = IriStr::new("scheme:/.///foo")?;
// Not normalized in the sense of RFC 3986.
assert!(!iri.is_normalized_rfc3986());use iri_string::format::ToDedicatedString;
use iri_string::types::IriStr;
let iri = IriStr::new("scheme:relative/..//not-a-host")?;
// RFC 3986 normalization algorithm assumes the path part to be NOT opaque.
assert!(!iri.is_normalized_rfc3986());
let normalized = iri.normalize().to_dedicated_string();
assert_eq!(normalized, "scheme:/.//not-a-host");Returns true if the IRI is already normalized in the sense of
normalize_but_preserve_authorityless_relative_path method.
This returns the same result as
self.normalize_but_preserve_authorityless_relative_path().to_string() == self,
but does this more efficiently without heap allocation.
§Examples
use iri_string::format::ToDedicatedString;
use iri_string::types::IriStr;
let iri = IriStr::new("HTTP://example.COM/foo/./bar/%2e%2e/../baz?query#fragment")?;
assert!(!iri.is_normalized_but_authorityless_relative_path_preserved());
let normalized = iri
.normalize_but_preserve_authorityless_relative_path()
.to_dedicated_string();
assert_eq!(normalized, "http://example.com/baz?query#fragment");
assert!(normalized.is_normalized());use iri_string::format::ToDedicatedString;
use iri_string::types::IriStr;
let iri = IriStr::new("scheme:/.///foo")?;
// Already normalized in the sense of
// `normalize_but_opaque_authorityless_relative_path()` method.
assert!(iri.is_normalized_but_authorityless_relative_path_preserved());use iri_string::format::ToDedicatedString;
use iri_string::types::IriStr;
let iri = IriStr::new("scheme:relative/..//not-a-host")?;
// Relative path is treated as opaque since the autority component is absent.
assert!(iri.is_normalized_but_authorityless_relative_path_preserved());Sourcepub fn normalize(&self) -> Normalized<'_, RiStr<S>>
pub fn normalize(&self) -> Normalized<'_, RiStr<S>>
Returns the normalized IRI.
§Notes
For some abnormal IRIs, the normalization can produce semantically incorrect string that looks syntactically valid. To avoid security issues by this trap, the normalization algorithm by this crate automatically applies the workaround.
If you worry about this, test by RiStr::ensure_rfc3986_normalizable
method or Normalized::ensure_rfc3986_normalizable before using the
result string.
§Examples
use iri_string::format::ToDedicatedString;
use iri_string::types::IriStr;
let iri = IriStr::new("HTTP://example.COM/foo/./bar/%2e%2e/../baz?query#fragment")?;
let normalized = iri.normalize().to_dedicated_string();
assert_eq!(normalized, "http://example.com/baz?query#fragment");Returns the normalized IRI, but preserving dot segments in relative path if the authority component is absent.
This normalization would be similar to that of WHATWG URL Standard while this implementation is not guaranteed to stricly follow the spec.
Note that this normalization algorithm is not compatible with RFC 3986 algorithm for some inputs.
Note that case normalization and percent-encoding normalization will still be applied to any path.
§Examples
use iri_string::format::ToDedicatedString;
use iri_string::types::IriStr;
let iri = IriStr::new("HTTP://example.COM/foo/./bar/%2e%2e/../baz?query#fragment")?;
let normalized = iri
.normalize_but_preserve_authorityless_relative_path()
.to_dedicated_string();
assert_eq!(normalized, "http://example.com/baz?query#fragment");use iri_string::format::ToDedicatedString;
use iri_string::types::IriStr;
let iri = IriStr::new("scheme:relative/../f%6f%6f")?;
let normalized = iri
.normalize_but_preserve_authorityless_relative_path()
.to_dedicated_string();
assert_eq!(normalized, "scheme:relative/../foo");
// `.normalize()` would normalize this to `scheme:/foo`.Sourcepub fn mask_password(&self) -> PasswordMasked<'_, RiStr<S>>
pub fn mask_password(&self) -> PasswordMasked<'_, RiStr<S>>
Returns the proxy to the IRI with password masking feature.
§Examples
use iri_string::format::ToDedicatedString;
use iri_string::types::IriStr;
let iri = IriStr::new("http://user:password@example.com/path?query")?;
let masked = iri.mask_password();
assert_eq!(masked.to_dedicated_string(), "http://user:@example.com/path?query");
assert_eq!(
masked.replace_password("${password}").to_string(),
"http://user:${password}@example.com/path?query"
);Sourcepub fn scheme_str(&self) -> &str
pub fn scheme_str(&self) -> &str
Returns the scheme.
The following colon is truncated.
§Examples
use iri_string::types::IriStr;
let iri = IriStr::new("http://example.com/pathpath?queryquery#fragfrag")?;
assert_eq!(iri.scheme_str(), "http");Returns the authority.
The leading // is truncated.
§Examples
use iri_string::types::IriStr;
let iri = IriStr::new("http://example.com/pathpath?queryquery#fragfrag")?;
assert_eq!(iri.authority_str(), Some("example.com"));use iri_string::types::IriStr;
let iri = IriStr::new("urn:uuid:10db315b-fcd1-4428-aca8-15babc9a2da2")?;
assert_eq!(iri.authority_str(), None);Sourcepub fn path_str(&self) -> &str
pub fn path_str(&self) -> &str
Returns the path.
§Examples
use iri_string::types::IriStr;
let iri = IriStr::new("http://example.com/pathpath?queryquery#fragfrag")?;
assert_eq!(iri.path_str(), "/pathpath");use iri_string::types::IriStr;
let iri = IriStr::new("urn:uuid:10db315b-fcd1-4428-aca8-15babc9a2da2")?;
assert_eq!(iri.path_str(), "uuid:10db315b-fcd1-4428-aca8-15babc9a2da2");Sourcepub fn query(&self) -> Option<&RiQueryStr<S>>
pub fn query(&self) -> Option<&RiQueryStr<S>>
Returns the query.
The leading question mark (?) is truncated.
§Examples
use iri_string::types::{IriQueryStr, IriStr};
let iri = IriStr::new("http://example.com/pathpath?queryquery#fragfrag")?;
let query = IriQueryStr::new("queryquery")?;
assert_eq!(iri.query(), Some(query));use iri_string::types::IriStr;
let iri = IriStr::new("urn:uuid:10db315b-fcd1-4428-aca8-15babc9a2da2")?;
assert_eq!(iri.query(), None);Sourcepub fn query_str(&self) -> Option<&str>
pub fn query_str(&self) -> Option<&str>
Returns the query in a raw string slice.
The leading question mark (?) is truncated.
§Examples
use iri_string::types::IriStr;
let iri = IriStr::new("http://example.com/pathpath?queryquery#fragfrag")?;
assert_eq!(iri.query_str(), Some("queryquery"));use iri_string::types::IriStr;
let iri = IriStr::new("urn:uuid:10db315b-fcd1-4428-aca8-15babc9a2da2")?;
assert_eq!(iri.query_str(), None);Sourcepub fn fragment(&self) -> Option<&RiFragmentStr<S>>
pub fn fragment(&self) -> Option<&RiFragmentStr<S>>
Returns the fragment part if exists.
A leading # character is truncated if the fragment part exists.
§Examples
let iri = IriStr::new("foo://bar/baz?qux=quux#corge")?;
let fragment = IriFragmentStr::new("corge")?;
assert_eq!(iri.fragment(), Some(fragment));let iri = IriStr::new("foo://bar/baz?qux=quux#")?;
let fragment = IriFragmentStr::new("")?;
assert_eq!(iri.fragment(), Some(fragment));let iri = IriStr::new("foo://bar/baz?qux=quux")?;
assert_eq!(iri.fragment(), None);Sourcepub fn fragment_str(&self) -> Option<&str>
pub fn fragment_str(&self) -> Option<&str>
Returns the fragment part as a raw string slice if exists.
A leading # character is truncated if the fragment part exists.
§Examples
let iri = IriStr::new("foo://bar/baz?qux=quux#corge")?;
assert_eq!(iri.fragment_str(), Some("corge"));let iri = IriStr::new("foo://bar/baz?qux=quux#")?;
assert_eq!(iri.fragment_str(), Some(""));let iri = IriStr::new("foo://bar/baz?qux=quux")?;
assert_eq!(iri.fragment_str(), None);Returns the authority components.
§Examples
use iri_string::types::IriStr;
let iri = IriStr::new("http://user:pass@example.com:8080/pathpath?queryquery")?;
let authority = iri.authority_components()
.expect("authority is available");
assert_eq!(authority.userinfo(), Some("user:pass"));
assert_eq!(authority.host(), "example.com");
assert_eq!(authority.port(), Some("8080"));use iri_string::types::IriStr;
let iri = IriStr::new("urn:uuid:10db315b-fcd1-4428-aca8-15babc9a2da2")?;
assert_eq!(iri.authority_str(), None);Sourcepub fn encode_to_uri(&self) -> MappedToUri<'_, RiStr<IriSpec>>
pub fn encode_to_uri(&self) -> MappedToUri<'_, RiStr<IriSpec>>
Percent-encodes the IRI into a valid URI that identifies the equivalent resource.
If you need more precise control over memory allocation and buffer
handling, use MappedToUri type.
§Examples
use iri_string::format::ToDedicatedString;
use iri_string::types::{IriStr, UriString};
let iri = IriStr::new("http://example.com/?alpha=\u{03B1}")?;
// Type annotation here is not necessary.
let uri: UriString = iri.encode_to_uri().to_dedicated_string();
assert_eq!(uri, "http://example.com/?alpha=%CE%B1");Sourcepub fn as_uri(&self) -> Option<&RiStr<UriSpec>>
pub fn as_uri(&self) -> Option<&RiStr<UriSpec>>
Converts an IRI into a URI without modification, if possible.
This is semantically equivalent to
UriStr::new(self.as_str()).ok().
§Examples
use iri_string::types::{IriStr, UriStr};
let ascii_iri = IriStr::new("http://example.com/?alpha=%CE%B1")?;
assert_eq!(
ascii_iri.as_uri().map(AsRef::as_ref),
Some("http://example.com/?alpha=%CE%B1")
);
let nonascii_iri = IriStr::new("http://example.com/?alpha=\u{03B1}")?;
assert_eq!(nonascii_iri.as_uri(), None);Trait Implementations§
Source§impl AsRef<RiReferenceStr<UriSpec>> for HttpUri
impl AsRef<RiReferenceStr<UriSpec>> for HttpUri
Source§fn as_ref(&self) -> &UriReferenceStr
fn as_ref(&self) -> &UriReferenceStr
Source§impl<'de> Deserialize<'de> for HttpUri
Available on crate feature serde only.
impl<'de> Deserialize<'de> for HttpUri
serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Predicate<HttpUri> for HasNoQuery
impl Predicate<HttpUri> for HasNoQuery
Source§impl Predicate<HttpUri> for IsAbsolute
impl Predicate<HttpUri> for IsAbsolute
Source§impl Predicate<HttpUri> for PathHasTrailingSlash
impl Predicate<HttpUri> for PathHasTrailingSlash
Source§impl SyncEvaluablePredicate<HttpUri> for HasNoQuery
impl SyncEvaluablePredicate<HttpUri> for HasNoQuery
Source§impl SyncEvaluablePredicate<HttpUri> for IsAbsolute
impl SyncEvaluablePredicate<HttpUri> for IsAbsolute
Source§impl SyncEvaluablePredicate<HttpUri> for IsNormal
impl SyncEvaluablePredicate<HttpUri> for IsNormal
Source§impl Term for HttpUri
Available on crate feature sophia only.
impl Term for HttpUri
sophia only.Source§type BorrowTerm<'x> = &'x HttpUri
type BorrowTerm<'x> = &'x HttpUri
Term that can be borrowed from this type
(i.e. that can be obtained from a simple reference to this type).
It is used in particular for accessing constituents of quoted tripes (Term::triple)
or for sharing this term with a function that expects T: Term (rather than &T)
using Term::borrow_term. Read moreSource§fn borrow_term(&self) -> Self::BorrowTerm<'_>
fn borrow_term(&self) -> Self::BorrowTerm<'_>
Source§fn is_blank_node(&self) -> bool
fn is_blank_node(&self) -> bool
Source§fn is_literal(&self) -> bool
fn is_literal(&self) -> bool
Source§fn is_variable(&self) -> bool
fn is_variable(&self) -> bool
Source§fn bnode_id(&self) -> Option<BnodeId<MownStr<'_>>>
fn bnode_id(&self) -> Option<BnodeId<MownStr<'_>>>
kind returns TermKind::BlankNode,
return the locally unique label of this blank node.
Otherwise return None. Read moreSource§fn lexical_form(&self) -> Option<MownStr<'_>>
fn lexical_form(&self) -> Option<MownStr<'_>>
kind returns TermKind::Literal,
return the lexical form of this literal.
Otherwise return None. Read moreSource§fn datatype(&self) -> Option<IriRef<MownStr<'_>>>
fn datatype(&self) -> Option<IriRef<MownStr<'_>>>
kind returns TermKind::Literal,
return the datatype IRI of this literal.
Otherwise return None. Read moreSource§fn language_tag(&self) -> Option<LanguageTag<MownStr<'_>>>
fn language_tag(&self) -> Option<LanguageTag<MownStr<'_>>>
kind returns TermKind::Literal,
and if this literal is a language-tagged string,
return its language tag.
Otherwise return None. Read moreSource§fn variable(&self) -> Option<VarName<MownStr<'_>>>
fn variable(&self) -> Option<VarName<MownStr<'_>>>
kind returns TermKind::Variable,
return the name of this variable.
Otherwise return None. Read moreSource§fn to_triple(self) -> Option<[Self; 3]>where
Self: Sized,
fn to_triple(self) -> Option<[Self; 3]>where
Self: Sized,
kind returns TermKind::Triple,
return this triple, consuming this term.
Otherwise return None. Read moreSource§fn constituents<'s>(
&'s self,
) -> Box<dyn Iterator<Item = Self::BorrowTerm<'s>> + 's>
fn constituents<'s>( &'s self, ) -> Box<dyn Iterator<Item = Self::BorrowTerm<'s>> + 's>
Source§fn to_constituents<'a>(self) -> Box<dyn Iterator<Item = Self> + 'a>where
Self: Clone + 'a,
fn to_constituents<'a>(self) -> Box<dyn Iterator<Item = Self> + 'a>where
Self: Clone + 'a,
Source§fn eq<T>(&self, other: T) -> boolwhere
T: Term,
fn eq<T>(&self, other: T) -> boolwhere
T: Term,
self and other represent the same RDF term.Source§fn hash<H>(&self, state: &mut H)where
H: Hasher,
fn hash<H>(&self, state: &mut H)where
H: Hasher,
Source§fn try_into_term<T>(self) -> Result<T, <T as TryFromTerm>::Error>where
T: TryFromTerm,
Self: Sized,
fn try_into_term<T>(self) -> Result<T, <T as TryFromTerm>::Error>where
T: TryFromTerm,
Self: Sized,
Source§fn as_simple(&self) -> SimpleTerm<'_>
fn as_simple(&self) -> SimpleTerm<'_>
SimpleTerm,
borrowing as much as possible from self
(calling SimpleTerm::from_term_ref).impl<SP: Predicate<HttpUri>> AuthorizedInferenceRuleGhost<IsNormal, HttpUri> for PhantomData<Normalization<SP>>
impl Eq for HttpUri
impl PreservingTransformGhost<IsAbsolute, HttpUri> for PhantomData<NormalizationTransform>
impl PurePredicate<HttpUri> for HasNoQuery
impl PurePredicate<HttpUri> for IsAbsolute
impl PurePredicate<HttpUri> for IsNormal
impl PurePredicate<HttpUri> for PathHasTrailingSlash
impl StructuralPartialEq for HttpUri
Auto Trait Implementations§
impl Freeze for HttpUri
impl RefUnwindSafe for HttpUri
impl Send for HttpUri
impl Sync for HttpUri
impl Unpin for HttpUri
impl UnwindSafe for HttpUri
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<Choices> CoproductSubsetter<CNil, HNil> for Choices
impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
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 moreSource§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.