summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/interfaces/bmcweb/eventservice/0001-Add-unmerged-changes-for-http-retry-support.patch
blob: 52135e2558efcd825ace6b2667153cafa23af28c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
From 6ff897d2b5513f15445f18aae16d8439ed94f377 Mon Sep 17 00:00:00 2001
From: P Dheeraj Srujan Kumar <p.dheeraj.srujan.kumar@intel.com>
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 <p.dheeraj.srujan.kumar@intel.com>
---
 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<HttpClient>
     std::optional<
         boost::beast::http::response_parser<boost::beast::http::string_body>>
         parser;
-    std::vector<std::pair<std::string, std::string>> headers;
     boost::circular_buffer_space_optimized<std::string> requestDataQueue{};
 
     ConnState state;
@@ -137,18 +136,6 @@ class HttpClient : public std::enable_shared_from_this<HttpClient>
 
         BMCWEB_LOG_DEBUG << __FUNCTION__ << "(): " << host << ":" << port;
 
-        req.version(static_cast<int>(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<HttpClient>
                 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<HttpClient>
                         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<HttpClient>
         return;
     }
 
-    void setHeaders(
+    void addHeaders(
         const std::vector<std::pair<std::string, std::string>>& 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