diff options
author | Ed Tanous <ed.tanous@intel.com> | 2018-04-27 02:08:56 +0300 |
---|---|---|
committer | Ed Tanous <ed.tanous@intel.com> | 2018-06-29 21:18:39 +0300 |
commit | 9bd21fc16817ab1a47e9cd4ac6baf8f5b1d4ba63 (patch) | |
tree | 6fd10d1f64bb80abced63fe1345a87b088766d43 /include/http_utility.hpp | |
parent | e0d918bc397350aa21af3dab9faa6e21748f6373 (diff) | |
download | bmcweb-9bd21fc16817ab1a47e9cd4ac6baf8f5b1d4ba63.tar.xz |
Fix issue with basic auth and the bmcweb
This fixes a bug where the webserver requests a resource that doesn't
exist, which triggers a www-authenticate, and causes the browser to
show the wrong thing.
Change-Id: I65643a50eb269b0a7c76dcb0c65c4e7db2165c88
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
Diffstat (limited to 'include/http_utility.hpp')
-rw-r--r-- | include/http_utility.hpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/include/http_utility.hpp b/include/http_utility.hpp new file mode 100644 index 0000000000..7b04b0f036 --- /dev/null +++ b/include/http_utility.hpp @@ -0,0 +1,21 @@ +#pragma once +#include <boost/algorithm/string.hpp> + +namespace http_helpers { +inline bool request_prefers_html(const crow::request& req) { + boost::string_view header = req.get_header_value("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
\ No newline at end of file |