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>
diff --git a/include/http_utility.hpp b/include/http_utility.hpp
index 46742a0..b7844ba 100644
--- a/include/http_utility.hpp
+++ b/include/http_utility.hpp
@@ -47,8 +47,15 @@
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;