1 #pragma once 2 #include <boost/algorithm/string.hpp> 3 4 namespace http_helpers { 5 inline bool requestPrefersHtml(const crow::Request& req) { 6 boost::string_view header = req.getHeaderValue("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