pub struct Url {
pub scheme: Scheme,
pub port: Option<u16>,
pub path: BString,
/* private fields */
}
Expand description
A URL with support for specialized git related capabilities.
Additionally there is support for deserialization and serialization
(see the Display::fmt()
implementation).
Deviation
Note that we do not support passing the password using the URL as it’s likely leading to accidents.
Fields§
§scheme: Scheme
The URL scheme.
port: Option<u16>
The port to use when connecting to a host. If None
, standard ports depending on scheme
will be used.
path: BString
The path portion of the URL, usually the location of the git repository.
Security-Warning
URLs allow paths to start with -
which makes it possible to mask command-line arguments as path which then leads to
the invocation of programs from an attacker controlled URL. See https://secure.phabricator.com/T12961 for details.
If this value is going to be used in a command-line application, call Self::path_argument_safe() instead.
Implementations§
source§impl Url
impl Url
Instantiation
sourcepub fn from_parts(
scheme: Scheme,
user: Option<String>,
password: Option<String>,
host: Option<String>,
port: Option<u16>,
path: BString,
serialize_alternative_form: bool
) -> Result<Url, Error>
pub fn from_parts( scheme: Scheme, user: Option<String>, password: Option<String>, host: Option<String>, port: Option<u16>, path: BString, serialize_alternative_form: bool ) -> Result<Url, Error>
Create a new instance from the given parts, including a password, which will be validated by parsing them back.
source§impl Url
impl Url
Builder
sourcepub fn serialize_alternate_form(self, use_alternate_form: bool) -> Url
pub fn serialize_alternate_form(self, use_alternate_form: bool) -> Url
Enable alternate serialization for this url, e.g. file:///path
becomes /path
.
This is automatically set correctly for parsed URLs, but can be set here for urls created by constructor.
source§impl Url
impl Url
Access
sourcepub fn host(&self) -> Option<&str>
pub fn host(&self) -> Option<&str>
Returns the host mentioned in the url, if present.
Security-Warning
URLs allow hosts to start with -
which makes it possible to mask command-line arguments as host which then leads to
the invocation of programs from an attacker controlled URL. See https://secure.phabricator.com/T12961 for details.
If this value is going to be used in a command-line application, call Self::host_argument_safe() instead.
sourcepub fn host_argument_safe(&self) -> Option<&str>
pub fn host_argument_safe(&self) -> Option<&str>
Return the host of this URL if present and if it can’t be mistaken for a command-line argument.
Use this method if the host is going to be passed to a command-line application.
sourcepub fn path_argument_safe(&self) -> Option<&BStr>
pub fn path_argument_safe(&self) -> Option<&BStr>
Return the path of this URL and if it can’t be mistaken for a command-line argument. Note that it always begins with a slash, which is ignored for this comparison.
Use this method if the path is going to be passed to a command-line application.
sourcepub fn path_is_root(&self) -> bool
pub fn path_is_root(&self) -> bool
Returns true if the path portion of the url is /
.
sourcepub fn port_or_default(&self) -> Option<u16>
pub fn port_or_default(&self) -> Option<u16>
Returns the actual or default port for use according to the url scheme. Note that there may be no default port either.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Url
impl<'de> Deserialize<'de> for Url
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<Url, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>( __deserializer: __D ) -> Result<Url, <__D as Deserializer<'de>>::Error>where __D: Deserializer<'de>,
source§impl Ord for Url
impl Ord for Url
source§impl PartialOrd<Url> for Url
impl PartialOrd<Url> for Url
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more