Ed Tanous | 9bd21fc | 2018-04-26 16:08:56 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | #include <boost/algorithm/string.hpp> |
| 3 | |
| 4 | namespace http_helpers { |
| 5 | inline 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 |