blob: e51e89cf98e71a1d02e73d8bbee4fd15a6ce79fe [file] [log] [blame]
Ed Tanous1fccd0d2024-03-19 09:16:16 -07001#include "http/parsing.hpp"
2
3#include <gtest/gtest.h>
4
5namespace
6{
7
8TEST(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
16 // Sites like mozilla show the space included [1]
17 // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
18 EXPECT_TRUE(isJsonContentType("application/json; charset=utf-8"));
19
20 EXPECT_TRUE(isJsonContentType("APPLICATION/JSON"));
21 EXPECT_TRUE(isJsonContentType("APPLICATION/JSON; CHARSET=UTF-8"));
22 EXPECT_TRUE(isJsonContentType("APPLICATION/JSON;CHARSET=UTF-8"));
23
24 EXPECT_FALSE(isJsonContentType("application/xml"));
25 EXPECT_FALSE(isJsonContentType(""));
26 EXPECT_FALSE(isJsonContentType(";"));
27 EXPECT_FALSE(isJsonContentType("application/json;"));
28 EXPECT_FALSE(isJsonContentType("application/json; "));
29 EXPECT_FALSE(isJsonContentType("application/json; charset=ascii"));
30 EXPECT_FALSE(isJsonContentType("json"));
31}
32} // namespace