| #include <boost/algorithm/string.hpp> |
| #include "http_request.h" |
| inline bool requestPrefersHtml(const crow::Request& req) |
| std::string_view header = req.getHeaderValue("accept"); |
| std::vector<std::string> encodings; |
| // chrome currently sends 6 accepts headers, firefox sends 4. |
| boost::split(encodings, header, boost::is_any_of(", "), |
| boost::token_compress_on); |
| for (const std::string& encoding : encodings) |
| if (encoding == "text/html") |
| else if (encoding == "application/json") |
| inline std::string urlEncode(const std::string_view value) |
| std::ostringstream escaped; |
| for (const char c : value) |
| // Keep alphanumeric and other accepted characters intact |
| if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') |
| // Any other characters are percent-encoded |
| escaped << std::uppercase; |
| escaped << '%' << std::setw(2) |
| << static_cast<int>(static_cast<unsigned char>(c)); |
| escaped << std::nouppercase; |
| } // namespace http_helpers |