From 50820f1a73e2a9084cff049e566f150f58b3de10 Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Tue, 22 Dec 2020 14:36:48 +0100 Subject: [PATCH] Provide a conversion function from icinga::String to boost::string_view Boost.Beast changed the signature of boost::beast::http::basic_fields::set in version 1.74 so that no longer allows passing an icinga::String instance as value. This adds a conversion function so that it works again. --- lib/base/string.cpp | 12 ++++++++++++ lib/base/string.hpp | 2 ++ 2 files changed, 14 insertions(+) diff --git a/lib/base/string.cpp b/lib/base/string.cpp index c4617e357..eec5b8372 100644 --- a/lib/base/string.cpp +++ b/lib/base/string.cpp @@ -127,6 +127,18 @@ String::operator const std::string&() const return m_Data; } +/** + * Conversion function to boost::string_view. + * + * This allows using String as the value for HTTP headers in boost::beast::http::basic_fields::set. + * + * @return A boost::string_view representing this string. + */ +String::operator boost::string_view() const +{ + return boost::string_view(m_Data); +} + const char *String::CStr() const { return m_Data.c_str(); diff --git a/lib/base/string.hpp b/lib/base/string.hpp index e9799e7eb..b9290eeee 100644 --- a/lib/base/string.hpp +++ b/lib/base/string.hpp @@ -6,6 +6,7 @@ #include "base/i2-base.hpp" #include "base/object.hpp" #include +#include #include #include @@ -71,6 +72,7 @@ public: bool operator<(const String& rhs) const; operator const std::string&() const; + operator boost::string_view() const; const char *CStr() const;