// SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: Copyright OpenBMC Authors #pragma once #include "http_request.hpp" #include #include #include #include namespace redfish { // Drop any incoming x-auth-token headers and keep Host and Content-Type. Set // Accept. inline crow::Request createNewRequest(const crow::Request& localReq) { boost::system::error_code ec; // Note, this is an expensive copy. It ideally shouldn't be done, but no // option at this point. crow::Request req(localReq.body(), ec); if (ec) { BMCWEB_LOG_ERROR("Failed to set body. Continuing"); } // Preserve method and target (URI) from the original request req.method(localReq.method()); if (!req.target(localReq.target())) { BMCWEB_LOG_ERROR("Failed to set target on aggregated request"); } for (const auto& field : localReq.fields()) { // Drop any incoming x-auth-token headers and keep Host and // Content-Type. Set Accept. auto headerName = field.name(); if (headerName == boost::beast::http::field::content_type || headerName == boost::beast::http::field::host) { req.addHeader(headerName, field.value()); } } // Set Accept header to application/json, application/octet-stream req.addHeader(boost::beast::http::field::accept, "application/json, application/octet-stream"); return req; } } // namespace redfish