Fix handling of ssl_key_handler for WebUI
The previous commit 90cd2e1 [1] causes WebUI to fail to load and
connect. It is because a global static var (`hasWebuiRoute`) is
instantiated per compile unit and it ends up causing the inconsistency
of the value of it.
Tested:
- Verify WebUI to load successful
- Redfish Service Validator passes
[1] https://github.com/openbmc/bmcweb/commit/90cd2e1d2e2228b0c575c9a3b6b2dc75eac9eb68
Change-Id: I09c3a9a831528e25c09299b0ee15993974d94d88
Signed-off-by: Myung Bae <myungbae@us.ibm.com>
diff --git a/include/forward_unauthorized.hpp b/include/forward_unauthorized.hpp
index 8914602..3891077 100644
--- a/include/forward_unauthorized.hpp
+++ b/include/forward_unauthorized.hpp
@@ -15,8 +15,11 @@
namespace forward_unauthorized
{
-// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
-static bool hasWebuiRoute = false;
+inline bool& hasWebuiRoute()
+{
+ static bool webuiRoute = false;
+ return webuiRoute;
+}
inline void sendUnauthorized(std::string_view url,
std::string_view xRequestedWith,
@@ -28,7 +31,7 @@
accept, http_helpers::ContentType::HTML, false /*allowWildcard*/))
{
// If we have a webui installed, redirect to that login page
- if (hasWebuiRoute)
+ if (hasWebuiRoute())
{
boost::urls::url forward =
boost::urls::format("/?next={}#/login", url);