diff options
-rw-r--r-- | src/other_tools/utils/curl_url_handle.cpp | 46 | ||||
-rw-r--r-- | src/other_tools/utils/curl_url_handle.hpp | 11 | ||||
-rw-r--r-- | test/other_tools/utils/curl_url.test.cpp | 24 |
3 files changed, 0 insertions, 81 deletions
diff --git a/src/other_tools/utils/curl_url_handle.cpp b/src/other_tools/utils/curl_url_handle.cpp index 33390ea6..27898299 100644 --- a/src/other_tools/utils/curl_url_handle.cpp +++ b/src/other_tools/utils/curl_url_handle.cpp @@ -790,52 +790,6 @@ auto CurlURLHandle::NoproxyStringMatches(std::string const& no_proxy) noexcept } } -auto CurlURLHandle::ReplaceHostname(std::string const& url, - std::string const& hostname) noexcept - -> std::optional<std::string> { - try { - // We should not guess the scheme based on current hostname, as it may - // cause the URL with the new hostname to falsely fail; we set - // use_default_scheme instead. Additionally, we set use_no_authority to - // false as the given URL MUST already have a hostname to be replaced. - if (auto parsed_url = CreatePermissive(url, - false /*use_guess_scheme*/, - true /*use_default_scheme*/, - true /*use_non_support_scheme*/, - false /*use_no_authority*/, - true /*use_path_as_is*/, - true /*use_allow_space*/, - true /*ignore_fatal*/)) { - if (*parsed_url == nullptr) { - return std::nullopt; - } - auto rc = curl_url_set(parsed_url.value()->handle_.get(), - CURLUPART_HOST, - hostname.c_str(), - 0U); - if (rc != CURLUE_OK) { - Logger::Log(LogLevel::Debug, - "CurlURLHandle: setting hostname {} in URL {} " - "failed with:\n{}", - hostname, - url, - curl_url_strerror(rc)); - return std::nullopt; - } - return parsed_url.value()->GetURL(false /*use_default_port*/, - true /*use_default_scheme*/, - false /*use_no_default_port*/, - true /*ignore_fatal*/); - } - } catch (std::exception const& ex) { - Logger::Log(LogLevel::Debug, - "CurlURLHandle: Replacing URL hostname failed unexpectedly " - "with:\n{}", - ex.what()); - } - return std::nullopt; -} - auto CurlURLHandle::GetHostname(std::string const& url) noexcept -> std::optional<std::string> { try { diff --git a/src/other_tools/utils/curl_url_handle.hpp b/src/other_tools/utils/curl_url_handle.hpp index 4680cb34..3d1e6949 100644 --- a/src/other_tools/utils/curl_url_handle.hpp +++ b/src/other_tools/utils/curl_url_handle.hpp @@ -154,17 +154,6 @@ 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>; - /// \brief Gets the hostname from URL. /// \returns The host name or std::nullopt if missing or on errors. [[nodiscard]] static auto GetHostname(std::string const& url) noexcept diff --git a/test/other_tools/utils/curl_url.test.cpp b/test/other_tools/utils/curl_url.test.cpp index 210092e3..61c979af 100644 --- a/test/other_tools/utils/curl_url.test.cpp +++ b/test/other_tools/utils/curl_url.test.cpp @@ -135,30 +135,6 @@ TEST_CASE("Curl URL handle basics", "[curl_url_handle_basics]") { CHECK(key_h.value()->port.value() == "80"); // default http port CHECK(key_h.value()->path.string() == "/foo/bar?query#fragment/"); } - - SECTION("Replace hostname") { - // full syntax check - auto new_url_full = CurlURLHandle::ReplaceHostname( - "https://user:pass@example.com:50000/some/" - "pa.th?what=what&who=who#fragment", - "example.org"); - CHECK(new_url_full); - CHECK(*new_url_full == - "https://user:pass@example.org:50000/some/" - "pa.th?what=what&who=who#fragment"); - - // non-supported scheme, path not normalized, spaces allowed - auto new_url_special = CurlURLHandle::ReplaceHostname( - "socks5://example.com/f oo/. ./ba r # b oo", "example.org"); - REQUIRE(new_url_special); - CHECK(*new_url_special == "socks5://example.org/f oo/. ./ba r # b oo"); - - // missing scheme does not fail, but new URL does contain default https - auto new_url_default_scheme = - CurlURLHandle::ReplaceHostname("192.0.2.1", "192.0.2.10"); - REQUIRE(new_url_default_scheme); - CHECK(*new_url_default_scheme == "https://192.0.2.10/"); - } } TEST_CASE("Curl URL match config key", "[curl_url_match_config_key]") { |