diff options
author | Ed Tanous <ed@tanous.net> | 2024-03-19 20:31:13 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2024-03-25 21:29:19 +0300 |
commit | a07e9819fbf24f998643812566f3ec3cf3a2204d (patch) | |
tree | 90118a8a15bdfece7de49d0bad0e815a4436df5d /http | |
parent | a10321e7924da96e6a11aa151347edf3314fed1c (diff) | |
download | bmcweb-a07e9819fbf24f998643812566f3ec3cf3a2204d.tar.xz |
Don't use switch for single conditional http2
This code was copied from one of the nghttp2 examples, and makes things
more complicated than they should be. We only handle one case here, so
a pattern of returning early is easier.
Also, this resolves a possible clang-tidy bugprone warning (that we
don't yet enable).
Tested: Http2 unit tests pass (good coverage for this case).
Change-Id: Ie8606872f3a96f1bb0329bf22a4f7429f431bbef
Signed-off-by: Ed Tanous <ed@tanous.net>
Diffstat (limited to 'http')
-rw-r--r-- | http/http2_connection.hpp | 78 |
1 files changed, 38 insertions, 40 deletions
diff --git a/http/http2_connection.hpp b/http/http2_connection.hpp index a698d9eb0d..7903ec93b1 100644 --- a/http/http2_connection.hpp +++ b/http/http2_connection.hpp @@ -396,49 +396,47 @@ class HTTP2Connection : BMCWEB_LOG_DEBUG("on_header_callback name: {} value {}", nameSv, valueSv); - - switch (frame.hd.type) + if (frame.hd.type != NGHTTP2_HEADERS) { - case NGHTTP2_HEADERS: - if (frame.headers.cat != NGHTTP2_HCAT_REQUEST) - { - break; - } - auto thisStream = streams.find(frame.hd.stream_id); - if (thisStream == streams.end()) - { - BMCWEB_LOG_ERROR("Unknown stream{}", frame.hd.stream_id); - close(); - return -1; - } + return 0; + } + if (frame.headers.cat != NGHTTP2_HCAT_REQUEST) + { + return 0; + } + auto thisStream = streams.find(frame.hd.stream_id); + if (thisStream == streams.end()) + { + BMCWEB_LOG_ERROR("Unknown stream{}", frame.hd.stream_id); + close(); + return -1; + } - crow::Request& thisReq = thisStream->second.req; + crow::Request& thisReq = thisStream->second.req; - if (nameSv == ":path") - { - thisReq.target(valueSv); - } - else if (nameSv == ":method") - { - boost::beast::http::verb verb = - boost::beast::http::string_to_verb(valueSv); - if (verb == boost::beast::http::verb::unknown) - { - BMCWEB_LOG_ERROR("Unknown http verb {}", valueSv); - close(); - return -1; - } - thisReq.req.method(verb); - } - else if (nameSv == ":scheme") - { - // Nothing to check on scheme - } - else - { - thisReq.req.set(nameSv, valueSv); - } - break; + if (nameSv == ":path") + { + thisReq.target(valueSv); + } + else if (nameSv == ":method") + { + boost::beast::http::verb verb = + boost::beast::http::string_to_verb(valueSv); + if (verb == boost::beast::http::verb::unknown) + { + BMCWEB_LOG_ERROR("Unknown http verb {}", valueSv); + close(); + return -1; + } + thisReq.req.method(verb); + } + else if (nameSv == ":scheme") + { + // Nothing to check on scheme + } + else + { + thisReq.req.set(nameSv, valueSv); } return 0; } |