summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGunnar Mills <gmills@us.ibm.com>2022-02-03 00:56:44 +0300
committerGunnar Mills <gmills@us.ibm.com>2022-08-22 23:30:17 +0300
commita3526fee27da0e324cd022ea77d282d1146b3317 (patch)
treeb6fd58b0fee19a0afba75ed7aaea0fd58d856e0f
parent0d4befa8f0b8c3fecb96f6c8c7acd26439ad122e (diff)
downloadbmcweb-a3526fee27da0e324cd022ea77d282d1146b3317.tar.xz
Remove q-factor weighting on Accept Header
bmcweb does not do anything with the q-factor weighting (;q=) so just remove it from the encoding. This is needed because routes like "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/attachment" have a check for isOctetAccepted. Even though */* is in the Accept Header isOctetAccepted still fails due to the q-factor weighting. On the system I tested, on firefox, Accept looks like: Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8 The GUI reported being unable to download a AdditionalDataURI (e.g. ...attachment/) Here is the GUI code attempting to download the additional data: https://github.com/openbmc/webui-vue/blob/9b79a6e7e3df3d3cbaf9a7750bbe343628022026/src/views/Logs/EventLogs/EventLogs.vue#L155 https://github.com/openbmc/webui-vue/blob/9b79a6e7e3df3d3cbaf9a7750bbe343628022026/src/locales/en-US.json#L251 Today this results in a 400 Bad Request due to isOctetAccepted. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept Tested: /redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/attachment/ and .../EventLog/Entries/<str>/attachment now return correctly. Change-Id: I969f5f2c32c4acccd4d80615f17c44d0c8fabd0d Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
-rw-r--r--include/http_utility.hpp9
-rw-r--r--include/ut/http_utility_test.cpp12
2 files changed, 19 insertions, 2 deletions
diff --git a/include/http_utility.hpp b/include/http_utility.hpp
index 46742a0ce6..b7844bacb8 100644
--- a/include/http_utility.hpp
+++ b/include/http_utility.hpp
@@ -47,8 +47,15 @@ inline bool requestPrefersHtml(std::string_view header)
inline bool isOctetAccepted(std::string_view header)
{
- for (const std::string& encoding : parseAccept(header))
+ for (std::string_view encoding : parseAccept(header))
{
+ // ignore any q-factor weighting (;q=)
+ std::size_t separator = encoding.find(";q=");
+
+ if (separator != std::string_view::npos)
+ {
+ encoding = encoding.substr(0, separator);
+ }
if (encoding == "*/*" || encoding == "application/octet-stream")
{
return true;
diff --git a/include/ut/http_utility_test.cpp b/include/ut/http_utility_test.cpp
index e412e17536..1a33fd8648 100644
--- a/include/ut/http_utility_test.cpp
+++ b/include/ut/http_utility_test.cpp
@@ -27,6 +27,16 @@ TEST(IsOctetAccepted, ContainsOctetReturnsTrue)
EXPECT_TRUE(isOctetAccepted("*/*, application/octet-stream"));
}
+TEST(IsOctetAccepted, ContainsAnyMimeTypeReturnsTrue)
+{
+ EXPECT_TRUE(http_helpers::isOctetAccepted("text/html, */*"));
+}
+
+TEST(IsOctetAccepted, ContainsQFactorWeightingReturnsTrue)
+{
+ EXPECT_TRUE(http_helpers::isOctetAccepted("text/html, */*;q=0.8"));
+}
+
TEST(IsOctetAccepted, NoOctetReturnsFalse)
{
EXPECT_FALSE(isOctetAccepted("text/html, application/json"));
@@ -34,4 +44,4 @@ TEST(IsOctetAccepted, NoOctetReturnsFalse)
}
} // namespace
-} // namespace http_helpers \ No newline at end of file
+} // namespace http_helpers