blob: f2d317206a3a420f09f6aa226ff9da1b71f9df47 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#pragma once
#include <boost/algorithm/string.hpp>
namespace http_helpers {
inline bool requestPrefersHtml(const crow::Request& req) {
boost::string_view header = req.getHeaderValue("accept");
std::vector<std::string> encodings;
// chrome currently sends 6 accepts headers, firefox sends 4.
encodings.reserve(6);
boost::split(encodings, header, boost::is_any_of(", "),
boost::token_compress_on);
for (const std::string& encoding : encodings) {
if (encoding == "text/html") {
return true;
} else if (encoding == "application/json") {
return false;
}
}
return false;
}
} // namespace http_helpers
|