bmcweb: avoid move in error conditions

Moving a response container is a bit non-sensical, and a little wasteful
when we're handling errors.  This commit moves to simply handling it
explicitly using the existing structures.

Change-Id: Idacf633741363945b57194730bd7c3427a23b38d
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
diff --git a/crow/include/crow/http_connection.h b/crow/include/crow/http_connection.h
index ba2bcdd..6f44186 100644
--- a/crow/include/crow/http_connection.h
+++ b/crow/include/crow/http_connection.h
@@ -323,7 +323,7 @@
             if (req->getHeaderValue(boost::beast::http::field::host).empty())
             {
                 isInvalidRequest = true;
-                res = Response(boost::beast::http::status::bad_request);
+                res.result(boost::beast::http::status::bad_request);
             }
         }
 
diff --git a/crow/include/crow/http_response.h b/crow/include/crow/http_response.h
index 093bd90..640197f 100644
--- a/crow/include/crow/http_response.h
+++ b/crow/include/crow/http_response.h
@@ -38,23 +38,6 @@
     {
     }
 
-    explicit Response(boost::beast::http::status code) :
-        stringResponse(response_type{})
-    {
-    }
-
-    explicit Response(std::string_view body_) : stringResponse(response_type{})
-    {
-        stringResponse->body() = std::string(body_);
-    }
-
-    Response(boost::beast::http::status code, std::string_view s) :
-        stringResponse(response_type{})
-    {
-        stringResponse->result(code);
-        stringResponse->body() = std::string(s);
-    }
-
     Response(Response&& r)
     {
         BMCWEB_LOG_DEBUG << "Moving response containers";
diff --git a/crow/include/crow/routing.h b/crow/include/crow/routing.h
index e657e2e..7d7a1b6 100644
--- a/crow/include/crow/routing.h
+++ b/crow/include/crow/routing.h
@@ -50,7 +50,7 @@
     virtual void handleUpgrade(const Request&, Response& res,
                                boost::asio::ip::tcp::socket&&)
     {
-        res = Response(boost::beast::http::status::not_found);
+        res.result(boost::beast::http::status::not_found);
         res.end();
     }
 #ifdef BMCWEB_ENABLE_SSL
@@ -58,7 +58,7 @@
         handleUpgrade(const Request&, Response& res,
                       boost::beast::ssl_stream<boost::asio::ip::tcp::socket>&&)
     {
-        res = Response(boost::beast::http::status::not_found);
+        res.result(boost::beast::http::status::not_found);
         res.end();
     }
 #endif
@@ -206,7 +206,7 @@
     {
         handler = [f = std::move(f)](const Request&, Response& res,
                                      Args... args) {
-            res = Response(f(args...));
+            res.result(f(args...));
             res.end();
         };
     }
@@ -219,7 +219,7 @@
 
         void operator()(const Request& req, Response& res, Args... args)
         {
-            res = Response(f(req, args...));
+            res.result(f(req, args...));
             res.end();
         }
 
@@ -242,7 +242,7 @@
         /*handler = (
             [f = std::move(f)]
             (const Request& req, Response& res, Args... args){
-                 res = Response(f(req, args...));
+                 res.result(f(req, args...));
                  res.end();
             });*/
     }
@@ -319,7 +319,7 @@
 
     void handle(const Request&, Response& res, const RoutingParams&) override
     {
-        res = Response(boost::beast::http::status::not_found);
+        res.result(boost::beast::http::status::not_found);
         res.end();
     }
 
@@ -533,7 +533,7 @@
 
         handler = [f = std::move(f)](const Request&, Response& res,
                                      Args... args) {
-            res = Response(f(args...));
+            res.result(f(args...));
             res.end();
         };
     }
@@ -560,7 +560,7 @@
 
         handler = [f = std::move(f)](const crow::Request& req,
                                      crow::Response& res, Args... args) {
-            res = Response(f(req, args...));
+            res.result(f(req, args...));
             res.end();
         };
     }
@@ -1085,7 +1085,7 @@
         if (!ruleIndex)
         {
             BMCWEB_LOG_DEBUG << "Cannot match rules " << req.url;
-            res = Response(boost::beast::http::status::not_found);
+            res.result(boost::beast::http::status::not_found);
             res.end();
             return;
         }
@@ -1097,7 +1097,7 @@
         {
             BMCWEB_LOG_INFO << "Redirecting to a url with trailing slash: "
                             << req.url;
-            res = Response(boost::beast::http::status::moved_permanently);
+            res.result(boost::beast::http::status::moved_permanently);
 
             // TODO absolute url building
             if (req.getHeaderValue("Host").empty())
@@ -1124,7 +1124,7 @@
                              << " with " << req.methodString() << "("
                              << (uint32_t)req.method() << ") / "
                              << rules[ruleIndex]->getMethods();
-            res = Response(boost::beast::http::status::not_found);
+            res.result(boost::beast::http::status::not_found);
             res.end();
             return;
         }
@@ -1141,7 +1141,7 @@
         catch (std::exception& e)
         {
             BMCWEB_LOG_ERROR << "An uncaught exception occurred: " << e.what();
-            res = Response(boost::beast::http::status::internal_server_error);
+            res.result(boost::beast::http::status::internal_server_error);
             res.end();
             return;
         }
@@ -1150,7 +1150,7 @@
             BMCWEB_LOG_ERROR
                 << "An uncaught exception occurred. The type was unknown "
                    "so no information was available.";
-            res = Response(boost::beast::http::status::internal_server_error);
+            res.result(boost::beast::http::status::internal_server_error);
             res.end();
             return;
         }
@@ -1183,7 +1183,7 @@
         {
             BMCWEB_LOG_INFO << "Redirecting to a url with trailing slash: "
                             << req.url;
-            res = Response(boost::beast::http::status::moved_permanently);
+            res.result(boost::beast::http::status::moved_permanently);
 
             // TODO absolute url building
             if (req.getHeaderValue("Host").empty())
@@ -1208,7 +1208,7 @@
                              << " with " << req.methodString() << "("
                              << (uint32_t)req.method() << ") / "
                              << rules[ruleIndex]->getMethods();
-            res = Response(boost::beast::http::status::not_found);
+            res.result(boost::beast::http::status::method_not_allowed);
             res.end();
             return;
         }
@@ -1225,7 +1225,7 @@
 
         if (!rules[ruleIndex]->checkPrivileges(userPrivileges))
         {
-            res.result(boost::beast::http::status::method_not_allowed);
+            res.result(boost::beast::http::status::unauthorized);
             res.end();
             return;
         }
@@ -1238,7 +1238,7 @@
         catch (std::exception& e)
         {
             BMCWEB_LOG_ERROR << "An uncaught exception occurred: " << e.what();
-            res = Response(boost::beast::http::status::internal_server_error);
+            res.result(boost::beast::http::status::internal_server_error);
             res.end();
             return;
         }
@@ -1247,7 +1247,7 @@
             BMCWEB_LOG_ERROR
                 << "An uncaught exception occurred. The type was unknown "
                    "so no information was available.";
-            res = Response(boost::beast::http::status::internal_server_error);
+            res.result(boost::beast::http::status::internal_server_error);
             res.end();
             return;
         }