summaryrefslogtreecommitdiff
path: root/include/http_utility.hpp
diff options
context:
space:
mode:
authorGeorge Liu <liuxiwei@inspur.com>2021-03-08 14:36:32 +0300
committerGeorge Liu <liuxiwei@inspur.com>2021-06-30 03:41:28 +0300
commitaf61db10fb40c7beb91a70f0b3ff28cb8e6c1704 (patch)
treefca36609e73134af0f36fda7e4649a32bd9b59bd /include/http_utility.hpp
parent0ef217f4e89016e8f49f487fe65934b934aab077 (diff)
downloadbmcweb-af61db10fb40c7beb91a70f0b3ff28cb8e6c1704.tar.xz
log_services: Add download of post code log entries
- Add a GET method /redfish/v1/Systems/system/LogServices/PostCodes /Entries/<str>/attachment/, Get the attribute value through the getPostCodes method and encode it as base64, and send it off. - This allows the use to offload error logs for analysis and further parsing if needed. An http header of "Accept: application/octet-stream" or the default "*/*" is expected. Tested: - Ran Redfish validator. - pldmtool raw --data 0x80 0x3F 0xC 0x0A 0x00 0x00 0x00 0x00 0x00 0x07 0x00 0x00 0x00 0x48 0x00 0x00 0x00 0x02 0x00 0x00 0x01 0x00 0x00 0x00 0x48 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x53 0x54 0x41 0x4e 0x44 0x42 0x59 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 $curl -k https://127.0.0.1:2443/redfish/v1/Systems/system/LogServices/PostCodes/Entries/B1-1/attachment/ output: AgAAAQAAAEgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFNUQU5EQlkgICAgICAgICAgICAgICAgICAgICAgICAg Signed-off-by: George Liu <liuxiwei@inspur.com> Change-Id: I74dd6c1dc2d3dfb7908f7741e0d9e7825c1df816
Diffstat (limited to 'include/http_utility.hpp')
-rw-r--r--include/http_utility.hpp33
1 files changed, 24 insertions, 9 deletions
diff --git a/include/http_utility.hpp b/include/http_utility.hpp
index 119a1eefb3..d04fd939fd 100644
--- a/include/http_utility.hpp
+++ b/include/http_utility.hpp
@@ -5,21 +5,24 @@
namespace http_helpers
{
+inline std::string parseAccept(const crow::Request& req)
+{
+ std::string_view acceptHeader = req.getHeaderValue("Accept");
+ // The iterators in boost/http/rfc7230.hpp end the string if '/' is found,
+ // so replace it with arbitrary character '|' which is not part of the
+ // Accept header syntax.
+ return boost::replace_all_copy(std::string(acceptHeader), "/", "|");
+}
+
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.
- encodings.reserve(6);
- boost::split(encodings, header, boost::is_any_of(", "),
- boost::token_compress_on);
- for (const std::string& encoding : encodings)
+ for (const auto& param : boost::beast::http::ext_list{parseAccept(req)})
{
- if (encoding == "text/html")
+ if (param.first == "text|html")
{
return true;
}
- if (encoding == "application/json")
+ if (param.first == "application|json")
{
return false;
}
@@ -27,6 +30,18 @@ inline bool requestPrefersHtml(const crow::Request& req)
return false;
}
+inline bool isOctetAccepted(const crow::Request& req)
+{
+ for (const auto& param : boost::beast::http::ext_list{parseAccept(req)})
+ {
+ if (param.first == "*|*" || param.first == "application|octet-stream")
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
inline std::string urlEncode(const std::string_view value)
{
std::ostringstream escaped;