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