Skip to main content

HttpUrl

Struct HttpUrl 

Source
pub struct HttpUrl { /* private fields */ }
Expand description

An immutable, parsed HTTP or HTTPS URL.

§Example

use http_url::HttpUrl;

let url = HttpUrl::parse("https://example.com/path?a=1#frag").unwrap();
assert_eq!(url.scheme(), "https");
assert_eq!(url.host(), "example.com");
assert_eq!(url.path(), "/path");
assert_eq!(url.query_parameter("a"), Some("1"));
assert_eq!(url.fragment(), Some("frag"));

Implementations§

Source§

impl HttpUrl

Source

pub fn parse(url: &str) -> Result<Self>

Parse a URL string into an HttpUrl.

The URL must have an http:// or https:// scheme.

Source§

impl HttpUrl

Source

pub fn builder() -> HttpUrlBuilder

Create a new builder.

Source

pub fn new_builder(&self) -> HttpUrlBuilder

Create a builder pre-populated with this URL’s components.

Source

pub fn scheme(&self) -> Scheme

Returns the URL scheme.

Source

pub fn is_https(&self) -> bool

Returns true if the scheme is https.

Source

pub fn username(&self) -> &str

Returns the username (empty string if not present).

Source

pub fn password(&self) -> &str

Returns the password (empty string if not present).

Source

pub fn host(&self) -> &str

Returns the host (domain, IPv4, or bracketed IPv6).

Source

pub fn port(&self) -> u16

The explicit port, or the default port for the scheme if none was set.

Source

pub fn explicit_port(&self) -> Option<u16>

The port only if it differs from the scheme’s default.

Source

pub fn path_segments(&self) -> &[String]

The decoded path segments.

Source

pub fn encoded_path(&self) -> String

The encoded path (with leading /), e.g. /a/b/c.

Source

pub fn path(&self) -> String

The decoded path as a string, e.g. /a/b/c.

Source

pub fn encoded_query(&self) -> Option<String>

Returns the query string (percent-encoded), or None if there are no parameters.

Source

pub fn query(&self) -> Option<String>

Returns the decoded query string, or None.

Source

pub fn query_parameter(&self, name: &str) -> Option<&str>

Get the first value for a query parameter name.

Source

pub fn query_parameters(&self, name: &str) -> Vec<&str>

Get all values for a query parameter name.

Source

pub fn query_parameter_names(&self) -> Vec<&str>

Returns the set of unique query parameter names.

Source

pub fn query_size(&self) -> usize

Number of query parameters.

Source

pub fn fragment(&self) -> Option<&str>

The fragment (decoded), if any.

Source

pub fn encoded_fragment(&self) -> Option<String>

The fragment (percent-encoded), if any.

Source

pub fn resolve(&self, link: &str) -> Result<HttpUrl>

Resolve a relative URL against this one.

This follows the algorithm from RFC 3986 Section 5.

Source

pub fn top_private_domain(&self) -> Option<String>

Compute the top private domain (eTLD+1) of this URL’s host.

Returns None if the host is an IP address or does not have enough domain labels. This is a simplified version; a full implementation would use the Public Suffix List.

Source

pub fn to_url_string(&self) -> String

The full URL string (percent-encoded).

Trait Implementations§

Source§

impl Clone for HttpUrl

Source§

fn clone(&self) -> HttpUrl

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 HttpUrl

Source§

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

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

impl Display for HttpUrl

Source§

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

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

impl Eq for HttpUrl

Source§

impl FromStr for HttpUrl

Source§

type Err = HttpUrlError

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

fn from_str(s: &str) -> Result<Self>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for HttpUrl

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for HttpUrl

Auto Trait Implementations§

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<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<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> 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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.