blob: f2d317206a3a420f09f6aa226ff9da1b71f9df47 [file] [log] [blame]
Ed Tanous9bd21fc2018-04-26 16:08:56 -07001#pragma once
2#include <boost/algorithm/string.hpp>
3
4namespace http_helpers {
Ed Tanous55c7b7a2018-05-22 15:27:24 -07005inline bool requestPrefersHtml(const crow::Request& req) {
6 boost::string_view header = req.getHeaderValue("accept");
Ed Tanous9bd21fc2018-04-26 16:08:56 -07007 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