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
impl HttpUrl
Sourcepub fn builder() -> HttpUrlBuilder
pub fn builder() -> HttpUrlBuilder
Create a new builder.
Sourcepub fn new_builder(&self) -> HttpUrlBuilder
pub fn new_builder(&self) -> HttpUrlBuilder
Create a builder pre-populated with this URL’s components.
Sourcepub fn port(&self) -> u16
pub fn port(&self) -> u16
The explicit port, or the default port for the scheme if none was set.
Sourcepub fn explicit_port(&self) -> Option<u16>
pub fn explicit_port(&self) -> Option<u16>
The port only if it differs from the scheme’s default.
Sourcepub fn path_segments(&self) -> &[String]
pub fn path_segments(&self) -> &[String]
The decoded path segments.
Sourcepub fn encoded_path(&self) -> String
pub fn encoded_path(&self) -> String
The encoded path (with leading /), e.g. /a/b/c.
Sourcepub fn encoded_query(&self) -> Option<String>
pub fn encoded_query(&self) -> Option<String>
Returns the query string (percent-encoded), or None if there are no parameters.
Sourcepub fn query_parameter(&self, name: &str) -> Option<&str>
pub fn query_parameter(&self, name: &str) -> Option<&str>
Get the first value for a query parameter name.
Sourcepub fn query_parameters(&self, name: &str) -> Vec<&str>
pub fn query_parameters(&self, name: &str) -> Vec<&str>
Get all values for a query parameter name.
Sourcepub fn query_parameter_names(&self) -> Vec<&str>
pub fn query_parameter_names(&self) -> Vec<&str>
Returns the set of unique query parameter names.
Sourcepub fn query_size(&self) -> usize
pub fn query_size(&self) -> usize
Number of query parameters.
Sourcepub fn encoded_fragment(&self) -> Option<String>
pub fn encoded_fragment(&self) -> Option<String>
The fragment (percent-encoded), if any.
Sourcepub fn resolve(&self, link: &str) -> Result<HttpUrl>
pub fn resolve(&self, link: &str) -> Result<HttpUrl>
Resolve a relative URL against this one.
This follows the algorithm from RFC 3986 Section 5.
Sourcepub fn top_private_domain(&self) -> Option<String>
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.
Sourcepub fn to_url_string(&self) -> String
pub fn to_url_string(&self) -> String
The full URL string (percent-encoded).