blob: e13dfc08781ba7563ff90739e921db16177106a0 [file] [log] [blame]
Ed Tanous9bd21fc2018-04-26 16:08:56 -07001#pragma once
2#include <boost/algorithm/string.hpp>
3
Ed Tanous1abe55e2018-09-05 08:30:59 -07004namespace http_helpers
5{
6inline bool requestPrefersHtml(const crow::Request& req)
7{
8 boost::string_view header = req.getHeaderValue("accept");
9 std::vector<std::string> encodings;
10 // chrome currently sends 6 accepts headers, firefox sends 4.
11 encodings.reserve(6);
12 boost::split(encodings, header, boost::is_any_of(", "),
13 boost::token_compress_on);
14 for (const std::string& encoding : encodings)
15 {
16 if (encoding == "text/html")
17 {
18 return true;
19 }
20 else if (encoding == "application/json")
21 {
22 return false;
23 }
Ed Tanous9bd21fc2018-04-26 16:08:56 -070024 }
Ed Tanous1abe55e2018-09-05 08:30:59 -070025 return false;
Ed Tanous9bd21fc2018-04-26 16:08:56 -070026}
Ed Tanous1abe55e2018-09-05 08:30:59 -070027} // namespace http_helpers