summaryrefslogtreecommitdiff
path: root/http/http_client.hpp
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2022-06-28 22:12:03 +0300
committerEd Tanous <edtanous@google.com>2023-05-30 23:56:15 +0300
commitf8ca6d79390b7f7fac5dbb82635dd6384810c668 (patch)
treeff1c55362a74f5a43d1c05d5d3924ab4d255f948 /http/http_client.hpp
parent86a5ac983f9715f7b1a0f8dee355906ac648e1d3 (diff)
downloadbmcweb-f8ca6d79390b7f7fac5dbb82635dd6384810c668.tar.xz
Allow async resolver to be optional
This commit adds a meson option to allow selecting which dns resolver bmcweb uses. There are use cases, like Open Compute Project Inband Management Agent, that would require not using dbus, which would require us to fall back to the asio resolver. This commit makes the existing asio resolver constructor, and async_resolve methods match the equivalents in asio (which we intended to do anyway), then adds a macro and configure option for being able to select which resolver backend to rely on. Tested: Code can now compile without sdbusplus. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I3220214367179f131a60082bdfaf7e725d35c125
Diffstat (limited to 'http/http_client.hpp')
-rw-r--r--http/http_client.hpp32
1 files changed, 20 insertions, 12 deletions
diff --git a/http/http_client.hpp b/http/http_client.hpp
index 2b498b7fb8..7a98b54497 100644
--- a/http/http_client.hpp
+++ b/http/http_client.hpp
@@ -146,7 +146,14 @@ class ConnectionInfo : public std::enable_shared_from_this<ConnectionInfo>
// Ascync callables
std::function<void(bool, uint32_t, Response&)> callback;
- crow::async_resolve::Resolver resolver;
+
+#ifdef BMCWEB_DBUS_DNS_RESOLVER
+ using Resolver = crow::async_resolve::Resolver;
+#else
+ using Resolver = boost::asio::ip::tcp::resolver;
+#endif
+ Resolver resolver;
+
boost::asio::ip::tcp::socket conn;
std::optional<boost::beast::ssl_stream<boost::asio::ip::tcp::socket&>>
sslConn;
@@ -162,15 +169,14 @@ class ConnectionInfo : public std::enable_shared_from_this<ConnectionInfo>
<< std::to_string(port)
<< ", id: " << std::to_string(connId);
- resolver.asyncResolve(host, port,
- std::bind_front(&ConnectionInfo::afterResolve,
- this, shared_from_this()));
+ resolver.async_resolve(host, std::to_string(port),
+ std::bind_front(&ConnectionInfo::afterResolve,
+ this, shared_from_this()));
}
- void afterResolve(
- const std::shared_ptr<ConnectionInfo>& /*self*/,
- const boost::beast::error_code& ec,
- const std::vector<boost::asio::ip::tcp::endpoint>& endpointList)
+ void afterResolve(const std::shared_ptr<ConnectionInfo>& /*self*/,
+ const boost::system::error_code& ec,
+ const Resolver::results_type& endpointList)
{
if (ec || (endpointList.empty()))
{
@@ -591,7 +597,7 @@ class ConnectionInfo : public std::enable_shared_from_this<ConnectionInfo>
unsigned int connIdIn) :
subId(idIn),
connPolicy(connPolicyIn), host(destIPIn), port(destPortIn),
- connId(connIdIn), conn(iocIn), timer(iocIn)
+ connId(connIdIn), resolver(iocIn), conn(iocIn), timer(iocIn)
{
if (useSSL)
{
@@ -833,8 +839,7 @@ class HttpClient
private:
std::unordered_map<std::string, std::shared_ptr<ConnectionPool>>
connectionPools;
- boost::asio::io_context& ioc =
- crow::connections::systemBus->get_io_context();
+ boost::asio::io_context& ioc;
std::shared_ptr<ConnectionPolicy> connPolicy;
// Used as a dummy callback by sendData() in order to call
@@ -847,9 +852,12 @@ class HttpClient
public:
HttpClient() = delete;
- explicit HttpClient(const std::shared_ptr<ConnectionPolicy>& connPolicyIn) :
+ explicit HttpClient(boost::asio::io_context& iocIn,
+ const std::shared_ptr<ConnectionPolicy>& connPolicyIn) :
+ ioc(iocIn),
connPolicy(connPolicyIn)
{}
+
HttpClient(const HttpClient&) = delete;
HttpClient& operator=(const HttpClient&) = delete;
HttpClient(HttpClient&&) = delete;