![]() |
Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
|
#include <url.hh>
Classes | |
| struct | Authority |
Public Member Functions | |
| std::string | renderAuthorityAndPath () const |
| std::string | to_string () const |
| std::string | renderPath (bool encode=false) const |
| auto | operator<=> (const ParsedURL &other) const noexcept=default |
| ParsedURL | canonicalise () |
| auto | pathSegments (bool skipEmpty) const & |
Public Attributes | |
| std::string | scheme |
| std::optional< Authority > | authority |
| std::vector< std::string > | path |
| StringMap | query |
| std::string | fragment |
Represents a parsed RFC3986 URL.
| ParsedURL nix::ParsedURL::canonicalise | ( | ) |
Remove . and .. path segments.
|
inline |
Get a range of path segments (the substrings separated by '/' characters).
| skipEmpty | Skip all empty path segments |
| std::string nix::ParsedURL::renderAuthorityAndPath | ( | ) | const |
Render just the middle part of a URL, without the // which indicates whether the authority is present.
| std::string nix::ParsedURL::renderPath | ( | bool | encode = false | ) | const |
Render the path to a string.
| encode | Whether to percent encode path segments. |
| std::optional<Authority> nix::ParsedURL::authority |
Optional parsed authority component of the URL.
IMPORTANT: An empty authority (i.e. one with an empty host string) and a missing authority (std::nullopt) are drastically different cases. This is especially important for "file:///path/to/file" URLs defined by RFC8089. The presence of the authority is indicated by // following the <scheme>: part of the URL.
| std::vector<std::string> nix::ParsedURL::path |
For an example, the path
is parsed as
We're doing splitting and joining that assumes the separator (/ in this case) only goes between elements.
That means the parsed representation will begin with an empty element to make an initial /, and will end with an ementy element to make a trailing /. That means that elements of this vector mostly, but not always, correspond to segments of the path.
Examples:
Note that both trailing and leading slashes are, in general, semantically significant.
For trailing slashes, the main example affecting many schemes is that ../baz resolves against a base URL different depending on the presence/absence of a trailing slash:
See parseURLRelative for more details.
For leading slashes, there are some requirements to be aware of.
When there is an authority, the path must start with a leading slash. Otherwise the path will not be separated from the authority, and will not round trip though the parser:
will render to https://foobar. but that would parse back as as
When there is no authority, the path must not begin with two slashes. Otherwise, there will be another parser round trip issue:
will render to https://bad. but that would parse back as as
These invariants will be checked in to_string and renderAuthorityAndPath.