summaryrefslogtreecommitdiff
path: root/include/webassets.hpp
diff options
context:
space:
mode:
authorEd Tanous <ed.tanous@intel.com>2019-10-24 20:10:07 +0300
committerEd Tanous <ed@tanous.net>2020-08-27 21:37:18 +0300
commit218bd4746130aac22366968c8c9a34a929e45a3d (patch)
tree817cb248aa0665f383d45e7b7cdc4fb8824edf08 /include/webassets.hpp
parentebd459060ea4f42761402dd54acd0962c36136c2 (diff)
downloadbmcweb-218bd4746130aac22366968c8c9a34a929e45a3d.tar.xz
Move webassets structures to constexpr
clang-tidy warned on some data structures that, if they throw, the exceptions can't be caught. Move these data structures to constexpr equivalents to save some memory. Tested: Loaded webui. Worked as intended, and static files loaded properly. Signed-off-by: Ed Tanous <ed@tanous.net> Change-Id: I331ebfc2451f0cc0a82a1b70d325008c9c80401a
Diffstat (limited to 'include/webassets.hpp')
-rw-r--r--include/webassets.hpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/include/webassets.hpp b/include/webassets.hpp
index 7cf6c93e3a..9944dfdb75 100644
--- a/include/webassets.hpp
+++ b/include/webassets.hpp
@@ -29,7 +29,7 @@ struct CmpStr
inline void requestRoutes(App& app)
{
- const static boost::container::flat_map<const char*, const char*, CmpStr>
+ constexpr static std::array<std::pair<const char*, const char*>, 17>
contentTypes{
{{".css", "text/css;charset=UTF-8"},
{".html", "text/html;charset=UTF-8"},
@@ -115,17 +115,24 @@ inline void requestRoutes(App& app)
}
const char* contentType = nullptr;
- auto contentTypeIt = contentTypes.find(extension.c_str());
- if (contentTypeIt == contentTypes.end())
+ for (const std::pair<const char*, const char*>& ext : contentTypes)
+ {
+ if (ext.first == nullptr || ext.second == nullptr)
+ {
+ continue;
+ }
+ if (extension == ext.first)
+ {
+ contentType = ext.second;
+ }
+ }
+
+ if (contentType == nullptr)
{
BMCWEB_LOG_ERROR << "Cannot determine content-type for "
<< absolutePath << " with extension "
<< extension;
}
- else
- {
- contentType = contentTypeIt->second;
- }
app.routeDynamic(webpath)(
[absolutePath, contentType,