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 <edtanous@google.com>
diff --git a/include/async_resolve.hpp b/include/async_resolve.hpp
index 3f31e13..71d2497 100644
--- a/include/async_resolve.hpp
+++ b/include/async_resolve.hpp
@@ -63,7 +63,7 @@
// 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 @@
uint64_t flag = 0;
crow::connections::systemBus->async_method_call(
- [host, portNum, handler{std::forward<ResolveHandler>(handler)}](
+ [host{std::string(host)}, portNum,
+ handler{std::forward<ResolveHandler>(handler)}](
const boost::system::error_code& ec,
const std::vector<
std::tuple<int32_t, int32_t, std::vector<uint8_t>>>& resp,
diff --git a/include/event_service_store.hpp b/include/event_service_store.hpp
index 61f1ac7..8b24fcb 100644
--- a/include/event_service_store.hpp
+++ b/include/event_service_store.hpp
@@ -3,6 +3,7 @@
#include <boost/beast/http/fields.hpp>
#include <boost/container/flat_map.hpp>
+#include <boost/url/parse.hpp>
#include <nlohmann/json.hpp>
namespace persistent_data
@@ -11,7 +12,7 @@
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 @@
{
continue;
}
- subvalue->destinationUrl = *value;
+ boost::urls::result<boost::urls::url> url =
+ boost::urls::parse_absolute_uri(*value);
+ if (!url)
+ {
+ continue;
+ }
+ subvalue->destinationUrl = std::move(*url);
}
else if (element.key() == "Protocol")
{