EventService: Pass httpHeaders to subscriber

Custom http headers provided by the subscriber was not passed on
to the http client request header

This commit passes the http headers to the Subscriber constructor

Tested by:
 Subscribe to events with custom headers
 Verify the event request packet sending the custom header to the
 subscriber
 Verified persistency of the subscription

Signed-off-by: Sunitha Harish <sunharis@in.ibm.com>
Change-Id: I9a4f59b6e9477fae96b380565885f4ac51e2a628
diff --git a/http/http_client.hpp b/http/http_client.hpp
index f45449b..0c9e387 100644
--- a/http/http_client.hpp
+++ b/http/http_client.hpp
@@ -197,8 +197,10 @@
                 if ((respCode < 200) || (respCode >= 300))
                 {
                     // The listener failed to receive the Sent-Event
-                    BMCWEB_LOG_ERROR << "recvMessage() Listener Failed to "
-                                        "receive Sent-Event";
+                    BMCWEB_LOG_ERROR
+                        << "recvMessage() Listener Failed to "
+                           "receive Sent-Event. Header Response Code: "
+                        << respCode;
                     self->state = ConnState::recvFailed;
                     self->handleConnState();
                     return;
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index b501265..010c991 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -383,9 +383,7 @@
         eventSeqNum(1),
         host(inHost), port(inPort), path(inPath), uriProto(inUriProto)
     {
-        conn = std::make_shared<crow::HttpClient>(
-            crow::connections::systemBus->get_io_context(), id, host, port,
-            path, httpHeaders);
+        // Subscription constructor
     }
 
     Subscription(const std::shared_ptr<boost::beast::tcp_stream>& adaptor) :
@@ -398,12 +396,17 @@
 
     void sendEvent(const std::string& msg)
     {
-        if (conn != nullptr)
+        if (conn == nullptr)
         {
-            conn->sendData(msg);
-            this->eventSeqNum++;
+            // create the HttpClient connection
+            conn = std::make_shared<crow::HttpClient>(
+                crow::connections::systemBus->get_io_context(), id, host, port,
+                path, httpHeaders);
         }
 
+        conn->sendData(msg);
+        eventSeqNum++;
+
         if (sseConn != nullptr)
         {
             sseConn->sendData(eventSeqNum, msg);