Remove fields member from Request

Per cpp core guidelines, we should be returning this via a function
call, not a direct member variable.  Doing this also improves the
safety, as we don't have to remember to move the references over in a
move.

Tested: Tested as part of top patch in series.

Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I837d6fd277ffa076ba5425003d6e6ee79204d014
diff --git a/http/http_request.hpp b/http/http_request.hpp
index 405db87..3a36a11 100644
--- a/http/http_request.hpp
+++ b/http/http_request.hpp
@@ -20,7 +20,6 @@
 struct Request
 {
     boost::beast::http::request<boost::beast::http::string_body> req;
-    boost::beast::http::fields& fields;
     std::string_view url{};
     boost::urls::url_view urlView{};
 
@@ -37,7 +36,7 @@
     Request(boost::beast::http::request<boost::beast::http::string_body> reqIn,
             std::error_code& ec) :
         req(std::move(reqIn)),
-        fields(req.base()), body(req.body())
+        body(req.body())
     {
         if (!setUrlInfo())
         {
@@ -46,18 +45,16 @@
     }
 
     Request(const Request& other) :
-        req(other.req), fields(req.base()), isSecure(other.isSecure),
-        body(req.body()), ioService(other.ioService),
-        ipAddress(other.ipAddress), session(other.session),
-        userRole(other.userRole)
+        req(other.req), isSecure(other.isSecure), body(req.body()),
+        ioService(other.ioService), ipAddress(other.ipAddress),
+        session(other.session), userRole(other.userRole)
     {
         setUrlInfo();
     }
 
     Request(Request&& other) noexcept :
-        req(std::move(other.req)), fields(req.base()), isSecure(other.isSecure),
-        body(req.body()), ioService(other.ioService),
-        ipAddress(std::move(other.ipAddress)),
+        req(std::move(other.req)), isSecure(other.isSecure), body(req.body()),
+        ioService(other.ioService), ipAddress(std::move(other.ipAddress)),
         session(std::move(other.session)), userRole(std::move(other.userRole))
     {
         setUrlInfo();
@@ -92,6 +89,11 @@
         return req.target();
     }
 
+    const boost::beast::http::fields& fields() const
+    {
+        return req.base();
+    }
+
     bool target(std::string_view target)
     {
         req.target(target);
diff --git a/redfish-core/include/redfish_aggregator.hpp b/redfish-core/include/redfish_aggregator.hpp
index 6c5cf76a..7ace802 100644
--- a/redfish-core/include/redfish_aggregator.hpp
+++ b/redfish-core/include/redfish_aggregator.hpp
@@ -596,7 +596,7 @@
         crow::HttpClient::getInstance().sendDataWithCallback(
             data, id, std::string(sat->second.host()),
             sat->second.port_number(), targetURI, false /*useSSL*/,
-            thisReq.fields, thisReq.method(), retryPolicyName, cb);
+            thisReq.fields(), thisReq.method(), retryPolicyName, cb);
     }
 
     // Forward a request for a collection URI to each known satellite BMC
@@ -615,7 +615,7 @@
             crow::HttpClient::getInstance().sendDataWithCallback(
                 data, id, std::string(sat.second.host()),
                 sat.second.port_number(), targetURI, false /*useSSL*/,
-                thisReq.fields, thisReq.method(), retryPolicyName, cb);
+                thisReq.fields(), thisReq.method(), retryPolicyName, cb);
         }
     }
 
diff --git a/redfish-core/lib/task.hpp b/redfish-core/lib/task.hpp
index 95fa0c0..2e7481a 100644
--- a/redfish-core/lib/task.hpp
+++ b/redfish-core/lib/task.hpp
@@ -63,7 +63,7 @@
             return;
         }
 
-        for (const auto& field : req.fields)
+        for (const auto& field : req.fields())
         {
             if (std::find(headerWhitelist.begin(), headerWhitelist.end(),
                           field.name()) == headerWhitelist.end())