Use enum overload for field setting
There are two overloads of addHeader, one that takes a string, and one
that takes a boost enum. For most common headers, boost contains a
string table with all of those entries anyway, so there's no point in
duplicating the strings, and ensures that we don't make trivial
mistakes, like capitalization or - versus underscore that aren't caught
at compile time.
Tested:
This saves a trivial amount (572 bytes) of compressed binary size.
curl --insecure -vvv --user root:0penBmc https://192.168.7.2/redfish/v1
returns < Content-Type: application/json
curl --insecure -vvv -H "Accept: text/html" --user root:0penBmc https://192.168.7.2/redfish/v1
Returns
< Content-Type: text/html;charset=UTF-8
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I34c198b4f9e219247fcfe719f9b3616d35aea3dc
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 7740014..34e9f73 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -1747,9 +1747,10 @@
std::string_view strData(data.data(), data.size());
std::string output = crow::utility::base64encode(strData);
- asyncResp->res.addHeader("Content-Type",
+ asyncResp->res.addHeader(boost::beast::http::field::content_type,
"application/octet-stream");
- asyncResp->res.addHeader("Content-Transfer-Encoding", "Base64");
+ asyncResp->res.addHeader(
+ boost::beast::http::field::content_transfer_encoding, "Base64");
asyncResp->res.body() = std::move(output);
},
"xyz.openbmc_project.Logging",
@@ -2971,7 +2972,8 @@
// Configure this to be a file download when accessed
// from a browser
- asyncResp->res.addHeader("Content-Disposition", "attachment");
+ asyncResp->res.addHeader(
+ boost::beast::http::field::content_disposition, "attachment");
};
crow::connections::systemBus->async_method_call(
std::move(getStoredLogCallback), crashdumpObject,
@@ -3620,9 +3622,10 @@
const char* d = reinterpret_cast<const char*>(c.data());
std::string_view strData(d, c.size());
- asyncResp->res.addHeader("Content-Type",
+ asyncResp->res.addHeader(boost::beast::http::field::content_type,
"application/octet-stream");
- asyncResp->res.addHeader("Content-Transfer-Encoding", "Base64");
+ asyncResp->res.addHeader(
+ boost::beast::http::field::content_transfer_encoding, "Base64");
asyncResp->res.body() = crow::utility::base64encode(strData);
},
"xyz.openbmc_project.State.Boot.PostCode0",