From 1873a04f43bb414408d1da9a5a775c05474603d2 Mon Sep 17 00:00:00 2001 From: Myung Bae Date: Mon, 1 Apr 2024 09:27:39 -0500 Subject: Reduce multi-level calls of req.req members Several places access the members of `req` indirectly like `req.req.method()`. This can be simplified as `req.method()` . This would also make the code clearer. Tested: - Compiles - Redfish service validator passes Change-Id: Ie129564ff907cdea7ac224b1e3d80cc0dedfbd7b Signed-off-by: Myung Bae --- http/http2_connection.hpp | 4 ++-- http/http_request.hpp | 9 +++++++++ http/websocket.hpp | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) (limited to 'http') diff --git a/http/http2_connection.hpp b/http/http2_connection.hpp index 4b1b2dcb91..8416ff738b 100644 --- a/http/http2_connection.hpp +++ b/http/http2_connection.hpp @@ -434,7 +434,7 @@ class HTTP2Connection : close(); return -1; } - thisReq.req.method(verb); + thisReq.method(verb); } else if (nameSv == ":scheme") { @@ -442,7 +442,7 @@ class HTTP2Connection : } else { - thisReq.req.set(nameSv, valueSv); + thisReq.addHeader(nameSv, valueSv); } return 0; } diff --git a/http/http_request.hpp b/http/http_request.hpp index a3c8fd8d0e..53f51e68fd 100644 --- a/http/http_request.hpp +++ b/http/http_request.hpp @@ -80,6 +80,10 @@ struct Request { return req.method(); } + void method(boost::beast::http::verb verb) + { + return req.method(verb); + } std::string_view getHeaderValue(std::string_view key) const { @@ -91,6 +95,11 @@ struct Request return req[key]; } + void clearHeader(boost::beast::http::field key) + { + req.erase(key); + } + std::string_view methodString() const { return req.method_string(); diff --git a/http/websocket.hpp b/http/websocket.hpp index d232c02330..2ef8412886 100644 --- a/http/websocket.hpp +++ b/http/websocket.hpp @@ -92,7 +92,8 @@ class ConnectionImpl : public Connection BMCWEB_LOG_DEBUG("starting connection {}", logPtr(this)); using bf = boost::beast::http::field; - std::string protocolHeader = req.req[bf::sec_websocket_protocol]; + std::string protocolHeader{ + req.getHeaderValue(bf::sec_websocket_protocol)}; ws.set_option(boost::beast::websocket::stream_base::decorator( [session{session}, -- cgit v1.2.3