blob: 164f51d90b79628b4dd13503522555a427785cbf [file] [log] [blame]
George Liu647b3cd2021-07-05 12:43:56 +08001#include <http_utility.hpp>
2
3#include "gmock/gmock.h"
4
5TEST(HttpUtility, requestPrefersHtml)
6{
7 boost::beast::http::request<boost::beast::http::string_body> req{};
8
9 req.set("Accept", "*/*, application/octet-stream");
10 crow::Request req1(req);
11 EXPECT_FALSE(
12 http_helpers::requestPrefersHtml(req1.getHeaderValue("Accept")));
13 EXPECT_TRUE(http_helpers::isOctetAccepted(req1.getHeaderValue("Accept")));
14
15 req.set("Accept", "text/html, application/json");
16 crow::Request req2(req);
17 EXPECT_TRUE(
18 http_helpers::requestPrefersHtml(req2.getHeaderValue("Accept")));
19 EXPECT_FALSE(http_helpers::isOctetAccepted(req2.getHeaderValue("Accept")));
20
21 req.set("Accept", "application/json");
22 crow::Request req3(req);
23 EXPECT_FALSE(
24 http_helpers::requestPrefersHtml(req3.getHeaderValue("Accept")));
25 EXPECT_FALSE(http_helpers::isOctetAccepted(req3.getHeaderValue("Accept")));
26}