Ed Tanous | 1fccd0d | 2024-03-19 09:16:16 -0700 | [diff] [blame] | 1 | #include "http/parsing.hpp" |
| 2 | |
| 3 | #include <gtest/gtest.h> |
| 4 | |
| 5 | namespace |
| 6 | { |
| 7 | |
| 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")); |
Ed Tanous | e4628c8 | 2024-12-16 10:57:04 -0800 | [diff] [blame] | 15 | EXPECT_TRUE(isJsonContentType("application/json;charset=ascii")); |
Ed Tanous | 1fccd0d | 2024-03-19 09:16:16 -0700 | [diff] [blame] | 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; ")); |
Ed Tanous | 1fccd0d | 2024-03-19 09:16:16 -0700 | [diff] [blame] | 30 | EXPECT_FALSE(isJsonContentType("json")); |
| 31 | } |
| 32 | } // namespace |