summaryrefslogtreecommitdiff
path: root/src/other_tools/utils/curl_url_handle.hpp
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-11-06 17:44:48 +0100
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-11-14 13:35:01 +0100
commitaf2409ef15993d97df342115b34799cc56558015 (patch)
tree7f78a954cc1b0dfdf210acb7b5d9f507386ae0a8 /src/other_tools/utils/curl_url_handle.hpp
parent8d656639aa07a9677a7c4c1ce8ce0a68287d99e5 (diff)
downloadjustbuild-af2409ef15993d97df342115b34799cc56558015.tar.gz
curl_url_handle: Add method to replace the hostname of a URL
Also adds a section in the curl_url test suite.
Diffstat (limited to 'src/other_tools/utils/curl_url_handle.hpp')
-rw-r--r--src/other_tools/utils/curl_url_handle.hpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/other_tools/utils/curl_url_handle.hpp b/src/other_tools/utils/curl_url_handle.hpp
index dfd278d7..5648a535 100644
--- a/src/other_tools/utils/curl_url_handle.hpp
+++ b/src/other_tools/utils/curl_url_handle.hpp
@@ -154,6 +154,17 @@ class CurlURLHandle {
[[nodiscard]] auto NoproxyStringMatches(
std::string const& no_proxy) noexcept -> std::optional<bool>;
+ /// \brief Tries to replace the hostname of a given URL. This is done by
+ /// parsing the URL with minimal validity checks, replacing the original
+ /// hostname with the one given, then putting the new URL back together.
+ /// \note The given URL MUST have a hostname for this to succeed.
+ /// \note A missing scheme field will be set to "https://" and a missing
+ /// path field will be set to "/".
+ /// \returns The new URL or nullopt on errors. This method is never fatal.
+ [[nodiscard]] static auto ReplaceHostname(
+ std::string const& url,
+ std::string const& hostname) noexcept -> std::optional<std::string>;
+
private:
// IMPORTANT: the CurlContext must be initialized before any curl
// object!