From 6ff897d2b5513f15445f18aae16d8439ed94f377 Mon Sep 17 00:00:00 2001 From: P Dheeraj Srujan Kumar Date: Mon, 11 Oct 2021 18:41:27 +0530 Subject: [PATCH] Add unmerged changes for http retry support The http retry support added upstream as a single patch was slpit into 3 patches, but only 2 of them was merged. This commit pulls in the differentail changes required to complete the entire http retry support. and also allow for other subsequent patches to be appplied easily. Change-Id: Id8ccd991b7ffc505196b1a92b23e1cd51e00bc89 Signed-off-by: P Dheeraj Srujan Kumar --- http/http_client.hpp | 44 +++++++++++-------- .../include/event_service_manager.hpp | 2 +- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/http/http_client.hpp b/http/http_client.hpp index ab20eb0..aad1cce 100644 --- a/http/http_client.hpp +++ b/http/http_client.hpp @@ -68,7 +68,6 @@ class HttpClient : public std::enable_shared_from_this std::optional< boost::beast::http::response_parser> parser; - std::vector> headers; boost::circular_buffer_space_optimized requestDataQueue{}; ConnState state; @@ -137,18 +136,6 @@ class HttpClient : public std::enable_shared_from_this BMCWEB_LOG_DEBUG << __FUNCTION__ << "(): " << host << ":" << port; - req.version(static_cast(11)); // HTTP 1.1 - req.target(uri); - req.method(boost::beast::http::verb::post); - - // Set headers - for (const auto& [key, value] : headers) - { - req.set(key, value); - } - req.set(boost::beast::http::field::host, host); - req.keep_alive(true); - req.body() = data; req.prepare_payload(); @@ -204,6 +191,17 @@ class HttpClient : public std::enable_shared_from_this BMCWEB_LOG_DEBUG << "recvMessage() data: " << self->parser->get(); + // Check if the response and header are received + if (!self->parser->is_done()) + { + // The parser failed to receive the response + BMCWEB_LOG_ERROR + << "recvMessage() parser failed to receive response"; + self->state = ConnState::recvFailed; + self->handleConnState(); + return; + } + unsigned int respCode = self->parser->get().result_int(); BMCWEB_LOG_DEBUG << "recvMessage() Header Response Code: " << respCode; @@ -398,11 +396,17 @@ class HttpClient : public std::enable_shared_from_this const std::string& destIP, const std::string& destPort, const std::string& destUri) : conn(ioc), - timer(ioc), subId(id), host(destIP), port(destPort), uri(destUri), - retryCount(0), maxRetryAttempts(5), retryIntervalSecs(0), + timer(ioc), req(boost::beast::http::verb::post, destUri, 11), + state(ConnState::initialized), subId(id), host(destIP), port(destPort), + uri(destUri), retryCount(0), maxRetryAttempts(5), retryIntervalSecs(0), retryPolicyAction("TerminateAfterRetries"), runningTimer(false) { - state = ConnState::initialized; + // Set the request header + req.set(boost::beast::http::field::host, host); + req.set(boost::beast::http::field::content_type, "application/json"); + req.keep_alive(true); + + requestDataQueue.set_capacity(maxRequestQueueSize); } void sendData(const std::string& data) @@ -425,10 +429,14 @@ class HttpClient : public std::enable_shared_from_this return; } - void setHeaders( + void addHeaders( const std::vector>& httpHeaders) { - headers = httpHeaders; + // Set custom headers + for (const auto& [key, value] : httpHeaders) + { + req.set(key, value); + } } void setRetryConfig(const uint32_t retryAttempts, diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp index 8042803..0a63b8c 100644 --- a/redfish-core/include/event_service_manager.hpp +++ b/redfish-core/include/event_service_manager.hpp @@ -412,7 +412,7 @@ class Subscription : public persistent_data::UserSubscription reqHeaders.emplace_back(std::pair(key, val)); } } - conn->setHeaders(reqHeaders); + conn->addHeaders(reqHeaders); conn->sendData(msg); this->eventSeqNum++; } -- 2.17.1