1897e4c80SChandramohan Harkude // SPDX-License-Identifier: Apache-2.0 2897e4c80SChandramohan Harkude // SPDX-FileCopyrightText: Copyright OpenBMC Authors 3897e4c80SChandramohan Harkude #pragma once 4897e4c80SChandramohan Harkude #include "http_request.hpp" 5897e4c80SChandramohan Harkude 6897e4c80SChandramohan Harkude #include <boost/beast/http/field.hpp> 7897e4c80SChandramohan Harkude #include <boost/beast/http/fields.hpp> 8897e4c80SChandramohan Harkude #include <boost/url/url.hpp> 9897e4c80SChandramohan Harkude 10897e4c80SChandramohan Harkude #include <memory> 11897e4c80SChandramohan Harkude namespace redfish 12897e4c80SChandramohan Harkude { 13897e4c80SChandramohan Harkude // Drop any incoming x-auth-token headers and keep Host and Content-Type. Set 14897e4c80SChandramohan Harkude // Accept. 15897e4c80SChandramohan Harkude inline crow::Request createNewRequest(const crow::Request& localReq) 16897e4c80SChandramohan Harkude { 17897e4c80SChandramohan Harkude boost::system::error_code ec; 18897e4c80SChandramohan Harkude // Note, this is an expensive copy. It ideally shouldn't be done, but no 19897e4c80SChandramohan Harkude // option at this point. 20897e4c80SChandramohan Harkude crow::Request req(localReq.body(), ec); 21897e4c80SChandramohan Harkude if (ec) 22897e4c80SChandramohan Harkude { 23897e4c80SChandramohan Harkude BMCWEB_LOG_ERROR("Failed to set body. Continuing"); 24897e4c80SChandramohan Harkude } 25897e4c80SChandramohan Harkude 26*456512bcSChandramohan Harkude // Preserve method and target (URI) from the original request 27*456512bcSChandramohan Harkude req.method(localReq.method()); 28*456512bcSChandramohan Harkude if (!req.target(localReq.target())) 29*456512bcSChandramohan Harkude { 30*456512bcSChandramohan Harkude BMCWEB_LOG_ERROR("Failed to set target on aggregated request"); 31*456512bcSChandramohan Harkude } 32*456512bcSChandramohan Harkude 33*456512bcSChandramohan Harkude for (const auto& field : localReq.fields()) 34897e4c80SChandramohan Harkude { 35897e4c80SChandramohan Harkude // Drop any incoming x-auth-token headers and keep Host and 36897e4c80SChandramohan Harkude // Content-Type. Set Accept. 37897e4c80SChandramohan Harkude auto headerName = field.name(); 38897e4c80SChandramohan Harkude if (headerName == boost::beast::http::field::content_type || 39897e4c80SChandramohan Harkude headerName == boost::beast::http::field::host) 40897e4c80SChandramohan Harkude { 41897e4c80SChandramohan Harkude req.addHeader(headerName, field.value()); 42897e4c80SChandramohan Harkude } 43897e4c80SChandramohan Harkude } 44*456512bcSChandramohan Harkude // Set Accept header to application/json, application/octet-stream 45897e4c80SChandramohan Harkude req.addHeader(boost::beast::http::field::accept, 46897e4c80SChandramohan Harkude "application/json, application/octet-stream"); 47897e4c80SChandramohan Harkude return req; 48897e4c80SChandramohan Harkude } 49897e4c80SChandramohan Harkude } // namespace redfish 50