summaryrefslogtreecommitdiff
path: root/http/http_client.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'http/http_client.hpp')
-rw-r--r--http/http_client.hpp48
1 files changed, 37 insertions, 11 deletions
diff --git a/http/http_client.hpp b/http/http_client.hpp
index 8c27d6d61a..4bae31d7de 100644
--- a/http/http_client.hpp
+++ b/http/http_client.hpp
@@ -148,6 +148,8 @@ class ConnectionInfo : public std::enable_shared_from_this<ConnectionInfo>
// Ascync callables
std::function<void(bool, uint32_t, Response&)> callback;
+ boost::asio::io_context& ioc;
+
#ifdef BMCWEB_DBUS_DNS_RESOLVER
using Resolver = async_resolve::Resolver;
#else
@@ -379,6 +381,16 @@ class ConnectionInfo : public std::enable_shared_from_this<ConnectionInfo>
unsigned int respCode = parser->get().result_int();
BMCWEB_LOG_DEBUG("recvMessage() Header Response Code: {}", respCode);
+ // Handle the case of stream_truncated. Some servers close the ssl
+ // connection uncleanly, so check to see if we got a full response
+ // before we handle this as an error.
+ if (!parser->is_done())
+ {
+ state = ConnState::recvFailed;
+ waitAndRetry();
+ return;
+ }
+
// Make sure the received response code is valid as defined by
// the associated retry policy
if (connPolicy->invalidResp(respCode))
@@ -487,7 +499,15 @@ class ConnectionInfo : public std::enable_shared_from_this<ConnectionInfo>
}
// Let's close the connection and restart from resolve.
- doClose(true);
+ shutdownConn(true);
+ }
+
+ void restartConnection()
+ {
+ BMCWEB_LOG_DEBUG("{}, id: {} restartConnection", host,
+ std::to_string(connId));
+ initializeConnection(host.scheme() == "https");
+ doResolve();
}
void shutdownConn(bool retry)
@@ -511,7 +531,7 @@ class ConnectionInfo : public std::enable_shared_from_this<ConnectionInfo>
{
// Now let's try to resend the data
state = ConnState::retry;
- doResolve();
+ restartConnection();
}
else
{
@@ -586,16 +606,10 @@ class ConnectionInfo : public std::enable_shared_from_this<ConnectionInfo>
}
}
- public:
- explicit ConnectionInfo(
- boost::asio::io_context& iocIn, const std::string& idIn,
- const std::shared_ptr<ConnectionPolicy>& connPolicyIn,
- boost::urls::url_view hostIn, unsigned int connIdIn) :
- subId(idIn),
- connPolicy(connPolicyIn), host(hostIn), connId(connIdIn),
- resolver(iocIn), conn(iocIn), timer(iocIn)
+ void initializeConnection(bool ssl)
{
- if (host.scheme() == "https")
+ conn = boost::asio::ip::tcp::socket(ioc);
+ if (ssl)
{
std::optional<boost::asio::ssl::context> sslCtx =
ensuressl::getSSLClientContext();
@@ -618,6 +632,18 @@ class ConnectionInfo : public std::enable_shared_from_this<ConnectionInfo>
setCipherSuiteTLSext();
}
}
+
+ public:
+ explicit ConnectionInfo(
+ boost::asio::io_context& iocIn, const std::string& idIn,
+ const std::shared_ptr<ConnectionPolicy>& connPolicyIn,
+ boost::urls::url_view hostIn, unsigned int connIdIn) :
+ subId(idIn),
+ connPolicy(connPolicyIn), host(hostIn), connId(connIdIn), ioc(iocIn),
+ resolver(iocIn), conn(iocIn), timer(iocIn)
+ {
+ initializeConnection(host.scheme() == "https");
+ }
};
class ConnectionPool : public std::enable_shared_from_this<ConnectionPool>