Connection and websockets fixes

This commit fixes issue around Connection class and websockets
  - controlling connection lifetime by shared_ptr instead of manual new/delete
  - fixed memory leak when upgrading connection to websockets
  - removed dangling reference to conn.req in websockets
  - fixed lack of reponse for invalid websockets URLs
  - fixed not working connections deadline timer

There is no noticable performance impact after switching connection management
to shared pointers. Benchmark results using: wrk https://${bmc}
	shared_ptr: 144.29 Requests/sec
	new/delete: 144.41 Requests/sec

Tested manually:
	performance: wrk https://${bmc}
	memory leaks: top
	websockets: webui- KVM and VirtualMedia
	HTTP GET on random Redfish schemas: postman

Signed-off-by: Jan Sowinski <jan.sowinski@intel.com>
Change-Id: I63f7395ba081a68e7900eae2ed204acd50f58689
diff --git a/http/http_server.h b/http/http_server.h
index df42214..6e63cbd 100644
--- a/http/http_server.h
+++ b/http/http_server.h
@@ -44,7 +44,8 @@
         ioService(std::move(io)),
         acceptor(std::move(acceptor)),
         signals(*ioService, SIGINT, SIGTERM, SIGHUP), tickTimer(*ioService),
-        handler(handler), middlewares(middlewares), adaptorCtx(adaptor_ctx)
+        timer(*ioService), handler(handler), middlewares(middlewares),
+        adaptorCtx(adaptor_ctx)
     {
     }
 
@@ -123,11 +124,9 @@
             return this->dateStr;
         };
 
-        boost::asio::steady_timer timer(*ioService);
         timer.expires_after(std::chrono::seconds(1));
 
-        std::function<void(const boost::system::error_code& ec)> timerHandler;
-        timerHandler = [&](const boost::system::error_code& ec) {
+        timerHandler = [this](const boost::system::error_code& ec) {
             if (ec)
             {
                 return;
@@ -231,8 +230,8 @@
                                        boost::asio::ip::tcp::socket>>::value)
         {
             adaptorTemp = Adaptor(*ioService, *adaptorCtx);
-            Connection<Adaptor, Handler, Middlewares...>* p =
-                new Connection<Adaptor, Handler, Middlewares...>(
+            auto p =
+                std::make_shared<Connection<Adaptor, Handler, Middlewares...>>(
                     *ioService, handler, serverName, middlewares,
                     getCachedDateStr, timerQueue,
                     std::move(adaptorTemp.value()));
@@ -245,18 +244,14 @@
                                                *this->ioService,
                                                [p] { p->start(); });
                                        }
-                                       else
-                                       {
-                                           delete p;
-                                       }
                                        doAccept();
                                    });
         }
         else
         {
             adaptorTemp = Adaptor(*ioService);
-            Connection<Adaptor, Handler, Middlewares...>* p =
-                new Connection<Adaptor, Handler, Middlewares...>(
+            auto p =
+                std::make_shared<Connection<Adaptor, Handler, Middlewares...>>(
                     *ioService, handler, serverName, middlewares,
                     getCachedDateStr, timerQueue,
                     std::move(adaptorTemp.value()));
@@ -268,10 +263,6 @@
                         boost::asio::post(*this->ioService,
                                           [p] { p->start(); });
                     }
-                    else
-                    {
-                        delete p;
-                    }
                     doAccept();
                 });
         }
@@ -284,6 +275,7 @@
     std::unique_ptr<tcp::acceptor> acceptor;
     boost::asio::signal_set signals;
     boost::asio::steady_timer tickTimer;
+    boost::asio::steady_timer timer;
 
     std::string dateStr;
 
@@ -292,6 +284,7 @@
 
     std::chrono::milliseconds tickInterval{};
     std::function<void()> tickFunction;
+    std::function<void(const boost::system::error_code& ec)> timerHandler;
 
     std::tuple<Middlewares...>* middlewares;