![]() |
Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
|
#include <filesystem>#include <ranges>#include <span>#include "nix/util/error.hh"#include "nix/util/canon-path.hh"#include "nix/util/split.hh"#include "nix/util/util.hh"#include "nix/util/variant-wrapper.hh"Go to the source code of this file.
Classes | |
| struct | nix::ParsedURL |
| struct | nix::ParsedURL::Authority |
| struct | nix::ParsedUrlScheme |
| struct | nix::VerbatimURL |
Functions | |
| std::ostream & | nix::operator<< (std::ostream &os, const ParsedURL &url) |
| nix::MakeError (BadURL, Error) | |
| std::string | nix::percentDecode (std::string_view in) |
| std::string | nix::percentEncode (std::string_view s, std::string_view keep="") |
| std::string | nix::renderUrlPathNoPctEncoding (std::span< const std::string > urlPath) |
| std::string | nix::encodeUrlPath (std::span< const std::string > urlPath) |
| StringMap | nix::decodeQuery (std::string_view query, bool lenient=false) |
| std::string | nix::encodeQuery (const StringMap &query) |
| ParsedURL | nix::parseURL (std::string_view url, bool lenient=false) |
| ParsedURL | nix::parseURLRelative (std::string_view url, const ParsedURL &base) |
| ParsedUrlScheme | nix::parseUrlScheme (std::string_view scheme) |
| ParsedURL | nix::fixGitURL (std::string url) |
| bool | nix::isValidSchemeName (std::string_view scheme) |
| std::vector< std::string > | nix::pathToUrlPath (const std::filesystem::path &path) |
| std::filesystem::path | nix::urlPathToPath (std::span< const std::string > urlPath) |
| std::ostream & | nix::operator<< (std::ostream &os, const VerbatimURL &url) |
| StringMap nix::decodeQuery | ( | std::string_view | query, |
| bool | lenient = false ) |
| lenient |
| std::string nix::encodeUrlPath | ( | std::span< const std::string > | urlPath | ) |
Percent encode path. %2F for "interior slashes" is the most important.
| ParsedURL nix::fixGitURL | ( | std::string | url | ) |
Detects scp-style uris (e.g. git@github.com:NixOS/nix) and fixes them by removing the : and assuming a scheme of ssh://. Also drops git+ from the scheme (e.g. git+https:// to https://) and changes absolute paths into file:// URLs.
ssh://[<user>@]<host>[:<port>]/<path-to-git-repo> git://<host>[:<port>]/<path-to-git-repo> http[s]://<host>[:<port>]/<path-to-git-repo> ftp[s]://<host>[:<port>]/<path-to-git-repo>
An alternative scp-like syntax may also be used with the ssh protocol: [<user>@]<host>:/<path-to-git-repo> This syntax is only recognized if there are no slashes before the first colon.
For local repositories, also supported by Git natively, the following syntaxes may be used: /path/to/repo.git/ file:///path/to/repo.git/
| bool nix::isValidSchemeName | ( | std::string_view | scheme | ) |
Whether a string is valid as RFC 3986 scheme name. Colon : is part of the URI; not the scheme name, and therefore rejected. See https://www.rfc-editor.org/rfc/rfc3986#section-3.1
Does not check whether the scheme is understood, as that's context-dependent.
| ParsedURL nix::parseURL | ( | std::string_view | url, |
| bool | lenient = false ) |
Parse a URL into a ParsedURL.
| lenient | Also allow some long-supported Nix URIs that are not quite compliant with RFC3986. Here are the deviations:
|
| BadURL |
The WHATWG specification of the URL constructor in Java Script is also a useful reference: https://url.spec.whatwg.org/#concept-basic-url-parser. Note, however, that it includes various scheme-specific normalizations / extra steps that we do not implement.
| ParsedURL nix::parseURLRelative | ( | std::string_view | url, |
| const ParsedURL & | base ) |
Like parseURL, but also accepts relative URLs, which are resolved against the given base URL.
This is specified in IETF RFC 3986, section 5
| BadURL |
Behavior should also match the new URL(url, base) JavaScript constructor, except for extra steps specific to the HTTP scheme. See parseURL for link to the relevant WHATWG standard.
| ParsedUrlScheme nix::parseUrlScheme | ( | std::string_view | scheme | ) |
Parse a URL scheme of the form '(applicationScheme+)?transportScheme' into a tuple '(applicationScheme, transportScheme)'
parseUrlScheme("http") == ParsedUrlScheme{ {}, "http"} parseUrlScheme("tarball+http") == ParsedUrlScheme{ {"tarball"}, "http"}
| std::vector< std::string > nix::pathToUrlPath | ( | const std::filesystem::path & | path | ) |
Convert a filesystem path to a URL path vector.
On Windows, converts backslashes to forward slashes and prepends a / before the drive letter (e.g., C:\foo\bar becomes /C:/foo/bar).
| std::string nix::renderUrlPathNoPctEncoding | ( | std::span< const std::string > | urlPath | ) |
Render URL path segments to a string by joining with /. Does not percent-encode the segments.
| std::filesystem::path nix::urlPathToPath | ( | std::span< const std::string > | urlPath | ) |
Convert a URL path vector to a native filesystem path.
On Windows, strips the leading / before the drive letter and converts to native format (e.g., /C:/foo/bar becomes C:\foo\bar).