diff options
author | Ed Tanous <edtanous@google.com> | 2022-06-29 20:05:19 +0300 |
---|---|---|
committer | Ed Tanous <edtanous@google.com> | 2022-12-15 23:03:47 +0300 |
commit | 079360ae6e04d3f2245e00d70f83d15c5cad3630 (patch) | |
tree | fcc89ce4e23a8fc63f18ad7ccf5cd044457861f0 /http/utility.hpp | |
parent | 0fb5b5051bebfe1330627a02d8f7c83195f71ed3 (diff) | |
download | bmcweb-079360ae6e04d3f2245e00d70f83d15c5cad3630.tar.xz |
Prepare for boost::url upgrade
The new boost URL now interops properly with std::string_view, which is
great, and cleans up a bunch of mediocre code to convert one to another.
It has also been pulled into boost-proper, so we no longer need a
boost-url dependency that's separate.
Unfortunately, boost url makes these improvements by changing
boost::string_view for boost::urls::const_string, which causes us to
have some compile errors on the missing type.
The bulk of these changes fall into a couple categories, and have to be
executed in one commit.
string() is replaced with buffer() on the url and url_view types
boost::string_view is replaced by std::string_view for many times, in
many cases removing a temporary that we had in the code previously.
Tested: Code compiles with boost 1.81.0 beta.
Redfish service validator passes.
Pretty good unit test coverage for URL-specific use cases.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I8d3dc89b53d1cc390887fe53605d4867f75f76fd
Diffstat (limited to 'http/utility.hpp')
-rw-r--r-- | http/utility.hpp | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/http/utility.hpp b/http/utility.hpp index b1b38da6f7..4f5cea74fd 100644 --- a/http/utility.hpp +++ b/http/utility.hpp @@ -4,7 +4,9 @@ #include <openssl/crypto.h> #include <boost/callable_traits.hpp> +#include <boost/url/parse.hpp> #include <boost/url/url.hpp> +#include <boost/url/url_view.hpp> #include <nlohmann/json.hpp> #include <array> @@ -616,13 +618,13 @@ class UrlSegmentMatcherVisitor public: UrlParseResult operator()(std::string& output) { - output = std::string_view(segment.data(), segment.size()); + output = segment; return UrlParseResult::Continue; } UrlParseResult operator()(std::string_view expected) { - if (std::string_view(segment.data(), segment.size()) == expected) + if (segment == expected) { return UrlParseResult::Continue; } @@ -634,13 +636,12 @@ class UrlSegmentMatcherVisitor return UrlParseResult::Done; } - explicit UrlSegmentMatcherVisitor( - const boost::urls::string_value& segmentIn) : + explicit UrlSegmentMatcherVisitor(std::string_view segmentIn) : segment(segmentIn) {} private: - const boost::urls::string_value& segment; + std::string_view segment; }; inline bool readUrlSegments(const boost::urls::url_view& urlView, @@ -766,9 +767,8 @@ inline bool validateAndSplitUrl(std::string_view destUrl, std::string& urlProto, std::string& host, uint16_t& port, std::string& path) { - boost::string_view urlBoost(destUrl.data(), destUrl.size()); boost::urls::result<boost::urls::url_view> url = - boost::urls::parse_uri(urlBoost); + boost::urls::parse_uri(destUrl); if (!url) { return false; @@ -781,11 +781,9 @@ inline bool validateAndSplitUrl(std::string_view destUrl, std::string& urlProto, port = setPortDefaults(url.value()); - host = std::string_view(url->encoded_host().data(), - url->encoded_host().size()); + host = url->encoded_host(); - path = std::string_view(url->encoded_path().data(), - url->encoded_path().size()); + path = url->encoded_path(); if (path.empty()) { path = "/"; @@ -793,15 +791,13 @@ inline bool validateAndSplitUrl(std::string_view destUrl, std::string& urlProto, if (url->has_fragment()) { path += '#'; - path += std::string_view(url->encoded_fragment().data(), - url->encoded_fragment().size()); + path += url->encoded_fragment(); } if (url->has_query()) { path += '?'; - path += std::string_view(url->encoded_query().data(), - url->encoded_query().size()); + path += url->encoded_query(); } return true; @@ -819,7 +815,7 @@ struct adl_serializer<boost::urls::url> // NOLINTNEXTLINE(readability-identifier-naming) static void to_json(json& j, const boost::urls::url& url) { - j = url.string(); + j = url.buffer(); } }; @@ -829,7 +825,7 @@ struct adl_serializer<boost::urls::url_view> // NOLINTNEXTLINE(readability-identifier-naming) static void to_json(json& j, const boost::urls::url_view& url) { - j = url.string(); + j = url.buffer(); } }; } // namespace nlohmann |