diff options
-rw-r--r-- | include/http_utility.hpp | 9 | ||||
-rw-r--r-- | include/ut/http_utility_test.cpp | 12 |
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 |