Remove body member from Request

Per cpp core guidelines, these should be methods.

Tested: on last patchset of the series.

Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ib16479db9d2b68da68e7ad6e825c7e205c64f1de
diff --git a/http/http_request.hpp b/http/http_request.hpp
index 3a36a11..e59f84b 100644
--- a/http/http_request.hpp
+++ b/http/http_request.hpp
@@ -25,8 +25,6 @@
 
     bool isSecure{false};
 
-    std::string& body;
-
     boost::asio::io_context* ioService{};
     boost::asio::ip::address ipAddress{};
 
@@ -35,8 +33,15 @@
     std::string userRole{};
     Request(boost::beast::http::request<boost::beast::http::string_body> reqIn,
             std::error_code& ec) :
-        req(std::move(reqIn)),
-        body(req.body())
+        req(std::move(reqIn))
+    {
+        if (!setUrlInfo())
+        {
+            ec = std::make_error_code(std::errc::invalid_argument);
+        }
+    }
+
+    Request(std::string_view bodyIn, std::error_code& ec) : req({}, bodyIn)
     {
         if (!setUrlInfo())
         {
@@ -45,15 +50,15 @@
     }
 
     Request(const Request& other) :
-        req(other.req), isSecure(other.isSecure), body(req.body()),
-        ioService(other.ioService), ipAddress(other.ipAddress),
-        session(other.session), userRole(other.userRole)
+        req(other.req), isSecure(other.isSecure), ioService(other.ioService),
+        ipAddress(other.ipAddress), session(other.session),
+        userRole(other.userRole)
     {
         setUrlInfo();
     }
 
     Request(Request&& other) noexcept :
-        req(std::move(other.req)), isSecure(other.isSecure), body(req.body()),
+        req(std::move(other.req)), isSecure(other.isSecure),
         ioService(other.ioService), ipAddress(std::move(other.ipAddress)),
         session(std::move(other.session)), userRole(std::move(other.userRole))
     {
@@ -94,6 +99,11 @@
         return req.base();
     }
 
+    const std::string& body() const
+    {
+        return req.body();
+    }
+
     bool target(std::string_view target)
     {
         req.target(target);
diff --git a/http/parsing.hpp b/http/parsing.hpp
index df63fca..f16d890 100644
--- a/http/parsing.hpp
+++ b/http/parsing.hpp
@@ -29,7 +29,7 @@
         return JsonParseResult::BadContentType;
 #endif
     }
-    jsonOut = nlohmann::json::parse(req.body, nullptr, false);
+    jsonOut = nlohmann::json::parse(req.body(), nullptr, false);
     if (jsonOut.is_discarded())
     {
         BMCWEB_LOG_WARNING << "Failed to parse json in request";