xref: /openbmc/bmcweb/test/http/parsing_test.cpp (revision e4628c813ed2bb828ba68f760d19d85e28213938)
1 #include "http/parsing.hpp"
2 
3 #include <gtest/gtest.h>
4 
5 namespace
6 {
7 
TEST(HttpParsing,isJsonContentType)8 TEST(HttpParsing, isJsonContentType)
9 {
10     EXPECT_TRUE(isJsonContentType("application/json"));
11 
12     // The Redfish specification DSP0266 shows no space between the ; and
13     // charset.
14     EXPECT_TRUE(isJsonContentType("application/json;charset=utf-8"));
15     EXPECT_TRUE(isJsonContentType("application/json;charset=ascii"));
16 
17     // Sites like mozilla show the space included [1]
18     //  https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
19     EXPECT_TRUE(isJsonContentType("application/json; charset=utf-8"));
20 
21     EXPECT_TRUE(isJsonContentType("APPLICATION/JSON"));
22     EXPECT_TRUE(isJsonContentType("APPLICATION/JSON; CHARSET=UTF-8"));
23     EXPECT_TRUE(isJsonContentType("APPLICATION/JSON;CHARSET=UTF-8"));
24 
25     EXPECT_FALSE(isJsonContentType("application/xml"));
26     EXPECT_FALSE(isJsonContentType(""));
27     EXPECT_FALSE(isJsonContentType(";"));
28     EXPECT_FALSE(isJsonContentType("application/json;"));
29     EXPECT_FALSE(isJsonContentType("application/json; "));
30     EXPECT_FALSE(isJsonContentType("json"));
31 }
32 } // namespace
33