pub struct UrlParser<'a> { /* private fields */ }
Expand description
A set of optional parameters for URL parsing.
Implementations§
source§impl<'a> UrlParser<'a>
impl<'a> UrlParser<'a>
A method-chaining API to provide a set of optional parameters for URL parsing.
sourcepub fn base_url<'b>(&'b mut self, value: &'a Url) -> &'b mut UrlParser<'a>
pub fn base_url<'b>(&'b mut self, value: &'a Url) -> &'b mut UrlParser<'a>
Set the base URL used for resolving relative URL references, and return the UrlParser
.
The default is no base URL, so that relative URLs references fail to parse.
sourcepub fn error_handler<'b>(
&'b mut self,
value: ErrorHandler,
) -> &'b mut UrlParser<'a>
pub fn error_handler<'b>( &'b mut self, value: ErrorHandler, ) -> &'b mut UrlParser<'a>
Set an error handler for non-fatal parse errors, and return the UrlParser
.
Non-fatal parse errors are normally ignored by the parser, but indicate violations of authoring requirements. An error handler can be used, for example, to log these errors in the console of a browser’s developer tools.
The error handler can choose to make the error fatal by returning Err(..)
sourcepub fn scheme_type_mapper<'b>(
&'b mut self,
value: fn(scheme: &str) -> SchemeType,
) -> &'b mut UrlParser<'a>
pub fn scheme_type_mapper<'b>( &'b mut self, value: fn(scheme: &str) -> SchemeType, ) -> &'b mut UrlParser<'a>
Set a scheme type mapper, and return the UrlParser
.
The URL parser behaves differently based on the SchemeType
of the URL.
See the documentation for SchemeType
for more details.
A scheme type mapper returns a SchemeType
based on the scheme as an ASCII lower case string,
as found in the scheme
field of an Url
struct.
The default scheme type mapper is as follows:
fn whatwg_scheme_type_mapper(scheme: &str) -> SchemeType {
match scheme {
"file" => SchemeType::FileLike,
"ftp" => SchemeType::Relative(21),
"gopher" => SchemeType::Relative(70),
"http" => SchemeType::Relative(80),
"https" => SchemeType::Relative(443),
"ws" => SchemeType::Relative(80),
"wss" => SchemeType::Relative(443),
_ => NonRelative,
}
}
Note that unknown schemes default to non-relative.
Overriding the scheme type mapper can allow, for example,
parsing URLs in the git
or irc
scheme as relative.
sourcepub fn parse(&self, input: &str) -> ParseResult<Url>
pub fn parse(&self, input: &str) -> ParseResult<Url>
Parse input
as an URL, with all the parameters previously set in the UrlParser
.
sourcepub fn parse_path(
&self,
input: &str,
) -> ParseResult<(Vec<String>, Option<String>, Option<String>)>
pub fn parse_path( &self, input: &str, ) -> ParseResult<(Vec<String>, Option<String>, Option<String>)>
Parse input
as a “standalone” URL path,
with an optional query string and fragment identifier.
This is typically found in the start line of an HTTP header.
Note that while the start line has no fragment identifier in the HTTP RFC, servers typically parse it and ignore it (rather than having it be part of the path or query string.)
On success, return (path, query_string, fragment_identifier)