Make Request copy explicit
It is currently too easy to accidentally make copies of the Request
object. Ideally code would parse out the Request in the first handler,
then no longer require an async copy. There is one case in the redfish
query things where we actually need a copy of the request object, so we
need these constructors, but we should make them explicit.
This commit moves the Request constructor to be private, and adds a new
method called copy() for explicitly making a copy. Ironcially, this
finds one place where we were actually making a copy of the request
object unintentionally, so fix that to only capture the value
required,the user session.
Tested:
- Compiles
- Run GET/PATCH related curl or If-Match like PATCH Account
- Redfish Service Validator runs and passes
Change-Id: I19255981f42757ed736112c003201e3f758735ac
Signed-off-by: Ed Tanous <ed@tanous.net>
Signed-off-by: Myung Bae <myungbae@us.ibm.com>
diff --git a/http/http_request.hpp b/http/http_request.hpp
index bfbe2e3..c2778ca 100644
--- a/http/http_request.hpp
+++ b/http/http_request.hpp
@@ -32,6 +32,8 @@
private:
boost::urls::url urlBase;
+ Request(const Request& other) = default;
+
public:
boost::asio::ip::address ipAddress;
@@ -51,13 +53,17 @@
Request() = default;
- Request(const Request& other) = default;
Request(Request&& other) = default;
- Request& operator=(const Request&) = default;
+ Request& operator=(const Request&) = delete;
Request& operator=(Request&&) = default;
~Request() = default;
+ Request copy() const
+ {
+ return {*this};
+ }
+
void addHeader(std::string_view key, std::string_view value)
{
req.insert(key, value);