Move isJSONContentType to content-type parser
Previously this function was based on a basic string comparison. This
is fine, but found several inconsistencies, like not handling spaces in
the appropriate places.
This commit creates a new function getContentType, using the new parsing
infrastructure. As doing this, it showed that the existing parser
functions were not handling case insensitive compares for the mime type.
While this is technically not required, it's something we unit test for,
and relatively easy to add.
Note, that because this parser ignores charset, this moves charset=ascii
from something that previously failed, to something that now succeeds.
This is expected.
Tested: Unit tests pass. Good coverage
Change-Id: I825a72862135b62112ee504ab0d9ead9d6796354
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/test/http/parsing_test.cpp b/test/http/parsing_test.cpp
index e51e89c..f35f761 100644
--- a/test/http/parsing_test.cpp
+++ b/test/http/parsing_test.cpp
@@ -12,6 +12,7 @@
// The Redfish specification DSP0266 shows no space between the ; and
// charset.
EXPECT_TRUE(isJsonContentType("application/json;charset=utf-8"));
+ EXPECT_TRUE(isJsonContentType("application/json;charset=ascii"));
// Sites like mozilla show the space included [1]
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
@@ -26,7 +27,6 @@
EXPECT_FALSE(isJsonContentType(";"));
EXPECT_FALSE(isJsonContentType("application/json;"));
EXPECT_FALSE(isJsonContentType("application/json; "));
- EXPECT_FALSE(isJsonContentType("application/json; charset=ascii"));
EXPECT_FALSE(isJsonContentType("json"));
}
} // namespace