From a716aa74954617e32a1d2e691d184580402b3eaf Mon Sep 17 00:00:00 2001 From: Ed Tanous Date: Tue, 1 Aug 2023 11:35:53 -0700 Subject: Move http client to URL Type safety is a good thing. In: https://gerrit.openbmc.org/c/openbmc/bmcweb/+/65606 It was found that splitting out the URI into encoded pieces in the early phase removed some information we needed, namely whether or not a URI was ipv6. This commit changes http client such that it passes all the information through, with the correct type, rather than passing in hostname, port, path, and ssl separately. Opportunistically, because a number of log lines are changing, this uses the opportunity to remove a number of calls to std::to_string, and rely on std::format instead. Now that we no longer use custom URI splitting code, the ValidateAndSplitUrl() method can be removed, given that our validation now happens in the URI class. Tested: Aggregation works properly when satellite URIs are queried. Change-Id: I9f605863179af54c5af2719bc5ce9d29cbfffab7 Signed-off-by: Ed Tanous --- include/async_resolve.hpp | 5 +++-- include/event_service_store.hpp | 11 +++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/async_resolve.hpp b/include/async_resolve.hpp index 3f31e1383f..71d2497e26 100644 --- a/include/async_resolve.hpp +++ b/include/async_resolve.hpp @@ -63,7 +63,7 @@ class Resolver // This function is kept using snake case so that it is interoperable with // boost::asio::ip::tcp::resolver // NOLINTNEXTLINE(readability-identifier-naming) - void async_resolve(const std::string& host, std::string_view port, + void async_resolve(std::string_view host, std::string_view port, ResolveHandler&& handler) { BMCWEB_LOG_DEBUG("Trying to resolve: {}:{}", host, port); @@ -82,7 +82,8 @@ class Resolver uint64_t flag = 0; crow::connections::systemBus->async_method_call( - [host, portNum, handler{std::forward(handler)}]( + [host{std::string(host)}, portNum, + handler{std::forward(handler)}]( const boost::system::error_code& ec, const std::vector< std::tuple>>& resp, diff --git a/include/event_service_store.hpp b/include/event_service_store.hpp index 61f1ac7b0f..8b24fcbe83 100644 --- a/include/event_service_store.hpp +++ b/include/event_service_store.hpp @@ -3,6 +3,7 @@ #include #include +#include #include namespace persistent_data @@ -11,7 +12,7 @@ namespace persistent_data struct UserSubscription { std::string id; - std::string destinationUrl; + boost::urls::url destinationUrl; std::string protocol; std::string retryPolicy; std::string customText; @@ -48,7 +49,13 @@ struct UserSubscription { continue; } - subvalue->destinationUrl = *value; + boost::urls::result url = + boost::urls::parse_absolute_uri(*value); + if (!url) + { + continue; + } + subvalue->destinationUrl = std::move(*url); } else if (element.key() == "Protocol") { -- cgit v1.2.3