xref: /openbmc/bmcweb/redfish-core/include/utils/redfish_aggregator_utils.hpp (revision 897e4c80f35b5bd963923f5794a7d3b229dba306)
1 // SPDX-License-Identifier: Apache-2.0
2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors
3 #pragma once
4 #include "http_request.hpp"
5 
6 #include <boost/beast/http/field.hpp>
7 #include <boost/beast/http/fields.hpp>
8 #include <boost/url/url.hpp>
9 
10 #include <memory>
11 namespace redfish
12 {
13 // Drop any incoming x-auth-token headers and keep Host and Content-Type. Set
14 // Accept.
createNewRequest(const crow::Request & localReq)15 inline crow::Request createNewRequest(const crow::Request& localReq)
16 {
17     boost::system::error_code ec;
18     // Note, this is an expensive copy.  It ideally shouldn't be done, but no
19     // option at this point.
20     crow::Request req(localReq.body(), ec);
21     if (ec)
22     {
23         BMCWEB_LOG_ERROR("Failed to set body.  Continuing");
24     }
25 
26     for (const auto& field : req.fields())
27     {
28         // Drop any incoming x-auth-token headers and keep Host and
29         // Content-Type. Set Accept.
30         auto headerName = field.name();
31         if (headerName == boost::beast::http::field::content_type ||
32             headerName == boost::beast::http::field::host)
33         {
34             req.addHeader(headerName, field.value());
35         }
36     }
37     req.addHeader(boost::beast::http::field::accept,
38                   "application/json, application/octet-stream");
39     return req;
40 }
41 } // namespace redfish
42