diff options
author | Ben Burdette <bburdette@users.noreply.github.com> | 2022-05-25 10:41:10 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-25 10:41:10 -0600 |
commit | 9a5ea6c359d5dc8a9a9c603a3c63ca808b04c15b (patch) | |
tree | e4a8f5e916b5a08fdfa82f723dae4499dec5bf69 /src/libutil | |
parent | 6031a36208dd174f05f094898d8ad35e5366106f (diff) | |
parent | d8398d33c9a09e1f5599127ae6d477e7e0868b55 (diff) |
Merge branch 'master' into debug-exploratory-PR
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/url.cc | 18 | ||||
-rw-r--r-- | src/libutil/url.hh | 15 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/libutil/url.cc b/src/libutil/url.cc index f6232d255..5b7abeb49 100644 --- a/src/libutil/url.cc +++ b/src/libutil/url.cc @@ -1,6 +1,7 @@ #include "url.hh" #include "url-parts.hh" #include "util.hh" +#include "split.hh" namespace nix { @@ -136,4 +137,21 @@ bool ParsedURL::operator ==(const ParsedURL & other) const && fragment == other.fragment; } +/** + * Parse a URL scheme of the form '(applicationScheme\+)?transportScheme' + * into a tuple '(applicationScheme, transportScheme)' + * + * > parseUrlScheme("http") == ParsedUrlScheme{ {}, "http"} + * > parseUrlScheme("tarball+http") == ParsedUrlScheme{ {"tarball"}, "http"} + */ +ParsedUrlScheme parseUrlScheme(std::string_view scheme) +{ + auto application = splitPrefixTo(scheme, '+'); + auto transport = scheme; + return ParsedUrlScheme { + .application = application, + .transport = transport, + }; +} + } diff --git a/src/libutil/url.hh b/src/libutil/url.hh index 6e77142e3..2a9fb34c1 100644 --- a/src/libutil/url.hh +++ b/src/libutil/url.hh @@ -27,4 +27,19 @@ std::map<std::string, std::string> decodeQuery(const std::string & query); ParsedURL parseURL(const std::string & url); +/* + * Although that’s not really standardized anywhere, an number of tools + * use a scheme of the form 'x+y' in urls, where y is the “transport layer” + * scheme, and x is the “application layer” scheme. + * + * For example git uses `git+https` to designate remotes using a Git + * protocol over http. + */ +struct ParsedUrlScheme { + std::optional<std::string_view> application; + std::string_view transport; +}; + +ParsedUrlScheme parseUrlScheme(std::string_view scheme); + } |