]> granicus.if.org Git - icinga2/commitdiff
HttpServerConnection: encapsulate streaming start indicator
authorAlexander A. Klimov <alexander.klimov@icinga.com>
Tue, 2 Apr 2019 15:37:29 +0000 (17:37 +0200)
committerAlexander A. Klimov <alexander.klimov@icinga.com>
Tue, 2 Apr 2019 15:37:29 +0000 (17:37 +0200)
34 files changed:
lib/remote/actionshandler.cpp
lib/remote/actionshandler.hpp
lib/remote/configfileshandler.cpp
lib/remote/configfileshandler.hpp
lib/remote/configpackageshandler.cpp
lib/remote/configpackageshandler.hpp
lib/remote/configstageshandler.cpp
lib/remote/configstageshandler.hpp
lib/remote/consolehandler.cpp
lib/remote/consolehandler.hpp
lib/remote/createobjecthandler.cpp
lib/remote/createobjecthandler.hpp
lib/remote/deleteobjecthandler.cpp
lib/remote/deleteobjecthandler.hpp
lib/remote/eventshandler.cpp
lib/remote/eventshandler.hpp
lib/remote/httphandler.cpp
lib/remote/httphandler.hpp
lib/remote/httpserverconnection.cpp
lib/remote/httpserverconnection.hpp
lib/remote/infohandler.cpp
lib/remote/infohandler.hpp
lib/remote/modifyobjecthandler.cpp
lib/remote/modifyobjecthandler.hpp
lib/remote/objectqueryhandler.cpp
lib/remote/objectqueryhandler.hpp
lib/remote/statushandler.cpp
lib/remote/statushandler.hpp
lib/remote/templatequeryhandler.cpp
lib/remote/templatequeryhandler.hpp
lib/remote/typequeryhandler.cpp
lib/remote/typequeryhandler.hpp
lib/remote/variablequeryhandler.cpp
lib/remote/variablequeryhandler.hpp

index 251f8a82e7f0539b92c782e9084e53c471240588..7b61cd5b9d52f22f4c84534494e0b55af2473224 100644 (file)
@@ -20,7 +20,7 @@ bool ActionsHandler::HandleRequest(
        boost::beast::http::response<boost::beast::http::string_body>& response,
        const Dictionary::Ptr& params,
        boost::asio::yield_context& yc,
-       bool& hasStartedStreaming
+       HttpServerConnection& server
 )
 {
        namespace http = boost::beast::http;
index 9c0463035813b6eea09a5ab2071c3cf5b5e8fcc4..c2465cf7e7579757067329ec42a9713065f67999 100644 (file)
@@ -21,7 +21,7 @@ public:
                boost::beast::http::response<boost::beast::http::string_body>& response,
                const Dictionary::Ptr& params,
                boost::asio::yield_context& yc,
-               bool& hasStartedStreaming
+               HttpServerConnection& server
        ) override;
 };
 
index 05def86553fb3c22040c26cb50e508c0ac84e794..d4c761c7b4db3467080b15284c3fa5e4df727372 100644 (file)
@@ -20,7 +20,7 @@ bool ConfigFilesHandler::HandleRequest(
        boost::beast::http::response<boost::beast::http::string_body>& response,
        const Dictionary::Ptr& params,
        boost::asio::yield_context& yc,
-       bool& hasStartedStreaming
+       HttpServerConnection& server
 )
 {
        namespace http = boost::beast::http;
index 1384c2b583bc486e95a54eb712417be4e53af63c..ea48b1ef4299229d416e3c835c9504e0069f4e23 100644 (file)
@@ -21,7 +21,7 @@ public:
                boost::beast::http::response<boost::beast::http::string_body>& response,
                const Dictionary::Ptr& params,
                boost::asio::yield_context& yc,
-               bool& hasStartedStreaming
+               HttpServerConnection& server
        ) override;
 };
 
index 2505de36aeee9d9b6c6cb87d6ecf78e1c58fc892..d9cd9ec9b4f98d7715aa02f56b804768fcb14474 100644 (file)
@@ -18,7 +18,7 @@ bool ConfigPackagesHandler::HandleRequest(
        boost::beast::http::response<boost::beast::http::string_body>& response,
        const Dictionary::Ptr& params,
        boost::asio::yield_context& yc,
-       bool& hasStartedStreaming
+       HttpServerConnection& server
 )
 {
        namespace http = boost::beast::http;
index 2ae184c6ab4d627011006b7ffabefaf5e4e1fa64..0a05ea10acf90809f1bb28b403dcc3ddb4538eeb 100644 (file)
@@ -21,7 +21,7 @@ public:
                boost::beast::http::response<boost::beast::http::string_body>& response,
                const Dictionary::Ptr& params,
                boost::asio::yield_context& yc,
-               bool& hasStartedStreaming
+               HttpServerConnection& server
        ) override;
 
 private:
index 067181f2757c65a78940bc7ee0bf67480dede6c3..a3c570a2fe8264750cfad5adbc205e8244371c9f 100644 (file)
@@ -19,7 +19,7 @@ bool ConfigStagesHandler::HandleRequest(
        boost::beast::http::response<boost::beast::http::string_body>& response,
        const Dictionary::Ptr& params,
        boost::asio::yield_context& yc,
-       bool& hasStartedStreaming
+       HttpServerConnection& server
 )
 {
        namespace http = boost::beast::http;
index 4ee35ad91cd5ad55253e1ff12171e4ca3cf805cc..c6d6443667fbf4658c9fd320efa35a36c00857ff 100644 (file)
@@ -21,7 +21,7 @@ public:
                boost::beast::http::response<boost::beast::http::string_body>& response,
                const Dictionary::Ptr& params,
                boost::asio::yield_context& yc,
-               bool& hasStartedStreaming
+               HttpServerConnection& server
        ) override;
 
 private:
index 430a37cf3c4ff68f68941772ed3d217fb84887b0..0f0fddc8f605e159da5363a687f11fca04a9a9e4 100644 (file)
@@ -61,7 +61,7 @@ bool ConsoleHandler::HandleRequest(
        boost::beast::http::response<boost::beast::http::string_body>& response,
        const Dictionary::Ptr& params,
        boost::asio::yield_context& yc,
-       bool& hasStartedStreaming
+       HttpServerConnection& server
 )
 {
        namespace http = boost::beast::http;
index 339f3ed86a238c59ea7cb9d3009d360275227e73..df0d77d01899a244d064fc7bd322e0110707188e 100644 (file)
@@ -30,7 +30,7 @@ public:
                boost::beast::http::response<boost::beast::http::string_body>& response,
                const Dictionary::Ptr& params,
                boost::asio::yield_context& yc,
-               bool& hasStartedStreaming
+               HttpServerConnection& server
        ) override;
 
        static std::vector<String> GetAutocompletionSuggestions(const String& word, ScriptFrame& frame);
index 1f7ab6710b8e203f414074223ef4125bf6ff8f23..c01b2364156f3d50f1b6579ede1e67917af66efd 100644 (file)
@@ -22,7 +22,7 @@ bool CreateObjectHandler::HandleRequest(
        boost::beast::http::response<boost::beast::http::string_body>& response,
        const Dictionary::Ptr& params,
        boost::asio::yield_context& yc,
-       bool& hasStartedStreaming
+       HttpServerConnection& server
 )
 {
        namespace http = boost::beast::http;
index ff42a62e6ac249c46b7fca51306bae04e7bf2550..4bcf21b55bc4ca8d9f7540cfa720d3fe9872a70b 100644 (file)
@@ -21,7 +21,7 @@ public:
                boost::beast::http::response<boost::beast::http::string_body>& response,
                const Dictionary::Ptr& params,
                boost::asio::yield_context& yc,
-               bool& hasStartedStreaming
+               HttpServerConnection& server
        ) override;
 };
 
index 15951588e018755374a7f0cc9d83d12f94102d65..2edb0e4551955d827c059a6958770d4182a768d3 100644 (file)
@@ -22,7 +22,7 @@ bool DeleteObjectHandler::HandleRequest(
        boost::beast::http::response<boost::beast::http::string_body>& response,
        const Dictionary::Ptr& params,
        boost::asio::yield_context& yc,
-       bool& hasStartedStreaming
+       HttpServerConnection& server
 )
 {
        namespace http = boost::beast::http;
index 3ecb0c71b5643393bed82614930c611b5cb42024..19a46e475e9d6ebfa60cf29975a4a1036b64f345 100644 (file)
@@ -21,7 +21,7 @@ public:
                boost::beast::http::response<boost::beast::http::string_body>& response,
                const Dictionary::Ptr& params,
                boost::asio::yield_context& yc,
-               bool& hasStartedStreaming
+               HttpServerConnection& server
        ) override;
 };
 
index e6f895cf3ea2005c78afc9b8b2bfc3b6b317734e..20f655f860c0006bcfe002bb55f9ebb78fc3581d 100644 (file)
@@ -25,7 +25,7 @@ bool EventsHandler::HandleRequest(
        boost::beast::http::response<boost::beast::http::string_body>& response,
        const Dictionary::Ptr& params,
        boost::asio::yield_context& yc,
-       bool& hasStartedStreaming
+       HttpServerConnection& server
 )
 {
        namespace asio = boost::asio;
@@ -88,7 +88,7 @@ bool EventsHandler::HandleRequest(
                EventQueue::UnregisterIfUnused(queueName, queue);
        });
 
-       hasStartedStreaming = true;
+       server.StartStreaming();
 
        response.result(http::status::ok);
        response.set(http::field::content_type, "application/json");
index cffeea5034f664e350830c76e6f26ea91083ebac..c823415d328071678d3a0e559067119eca982ba6 100644 (file)
@@ -22,7 +22,7 @@ public:
                boost::beast::http::response<boost::beast::http::string_body>& response,
                const Dictionary::Ptr& params,
                boost::asio::yield_context& yc,
-               bool& hasStartedStreaming
+               HttpServerConnection& server
        ) override;
 };
 
index c089c00ea51a157c6c69f83996d7f39899543ce8..78e09d2ade12c921d4aacb943e8fba5f0c193f8c 100644 (file)
@@ -51,7 +51,7 @@ void HttpHandler::ProcessRequest(
        boost::beast::http::request<boost::beast::http::string_body>& request,
        boost::beast::http::response<boost::beast::http::string_body>& response,
        boost::asio::yield_context& yc,
-       bool& hasStartedStreaming
+       HttpServerConnection& server
 )
 {
        Dictionary::Ptr node = m_UrlTree;
@@ -99,7 +99,7 @@ void HttpHandler::ProcessRequest(
 
        bool processed = false;
        for (const HttpHandler::Ptr& handler : handlers) {
-               if (handler->HandleRequest(stream, user, request, url, response, params, yc, hasStartedStreaming)) {
+               if (handler->HandleRequest(stream, user, request, url, response, params, yc, server)) {
                        processed = true;
                        break;
                }
index cec5f58cd1611721a4642764bbcae6a9f6705249..6c10d0affac9989222c67657f1fe7b1cb9ee6f81 100644 (file)
@@ -6,6 +6,7 @@
 #include "remote/i2-remote.hpp"
 #include "remote/url.hpp"
 #include "remote/httpresponse.hpp"
+#include "remote/httpserverconnection.hpp"
 #include "remote/apiuser.hpp"
 #include "base/registry.hpp"
 #include "base/tlsstream.hpp"
@@ -34,7 +35,7 @@ public:
                boost::beast::http::response<boost::beast::http::string_body>& response,
                const Dictionary::Ptr& params,
                boost::asio::yield_context& yc,
-               bool& hasStartedStreaming
+               HttpServerConnection& server
        ) = 0;
 
        static void Register(const Url::Ptr& url, const HttpHandler::Ptr& handler);
@@ -44,7 +45,7 @@ public:
                boost::beast::http::request<boost::beast::http::string_body>& request,
                boost::beast::http::response<boost::beast::http::string_body>& response,
                boost::asio::yield_context& yc,
-               bool& hasStartedStreaming
+               HttpServerConnection& server
        );
 
 private:
index af51699528173502c1647fa00fcb414b5f6035be..5c40e2e83f678488129a59c8d7d74e711a833ca3 100644 (file)
@@ -31,7 +31,7 @@ using namespace icinga;
 auto const l_ServerHeader ("Icinga/" + Application::GetAppVersion());
 
 HttpServerConnection::HttpServerConnection(const String& identity, bool authenticated, const std::shared_ptr<AsioTlsStream>& stream)
-       : m_Stream(stream), m_Seen(Utility::GetTime()), m_IoStrand(stream->get_io_service()), m_ShuttingDown(false)
+       : m_Stream(stream), m_Seen(Utility::GetTime()), m_IoStrand(stream->get_io_service()), m_ShuttingDown(false), m_HasStartedStreaming(false)
 {
        if (authenticated) {
                m_ApiUser = ApiUser::GetByClientCN(identity);
@@ -91,6 +91,11 @@ void HttpServerConnection::Disconnect()
        });
 }
 
+void HttpServerConnection::StartStreaming()
+{
+       m_HasStartedStreaming = true;
+}
+
 static inline
 bool EnsureValidHeaders(
        AsioTlsStream& stream,
@@ -375,17 +380,17 @@ bool ProcessRequest(
        boost::beast::http::request<boost::beast::http::string_body>& request,
        ApiUser::Ptr& authenticatedUser,
        boost::beast::http::response<boost::beast::http::string_body>& response,
+       HttpServerConnection& server,
+       bool& hasStartedStreaming,
        boost::asio::yield_context& yc
 )
 {
        namespace http = boost::beast::http;
 
-       bool hasStartedStreaming = false;
-
        try {
                CpuBoundWork handlingRequest (yc);
 
-               HttpHandler::ProcessRequest(stream, authenticatedUser, request, response, yc, hasStartedStreaming);
+               HttpHandler::ProcessRequest(stream, authenticatedUser, request, response, yc, server);
        } catch (const std::exception& ex) {
                if (hasStartedStreaming) {
                        return false;
@@ -481,7 +486,7 @@ void HttpServerConnection::ProcessMessages(boost::asio::yield_context yc)
 
                        m_Seen = std::numeric_limits<decltype(m_Seen)>::max();
 
-                       if (!ProcessRequest(*m_Stream, request, authenticatedUser, response, yc)) {
+                       if (!ProcessRequest(*m_Stream, request, authenticatedUser, response, *this, m_HasStartedStreaming, yc)) {
                                break;
                        }
 
index 7db97ed68207c5105e1d15981c861b8a80350143..56876829ca6b01b712410375ca998a8edd313c66 100644 (file)
@@ -27,6 +27,7 @@ public:
 
        void Start();
        void Disconnect();
+       void StartStreaming();
 
 private:
        ApiUser::Ptr m_ApiUser;
@@ -35,6 +36,7 @@ private:
        String m_PeerAddress;
        boost::asio::io_service::strand m_IoStrand;
        bool m_ShuttingDown;
+       bool m_HasStartedStreaming;
 
        void ProcessMessages(boost::asio::yield_context yc);
        void CheckLiveness(boost::asio::yield_context yc);
index 38f99781d01ac9d4c36d6b6c97c86698ecc36a71..d9d6b45cbddc72da4fb5993cebbf17b03563e2ef 100644 (file)
@@ -16,7 +16,7 @@ bool InfoHandler::HandleRequest(
        boost::beast::http::response<boost::beast::http::string_body>& response,
        const Dictionary::Ptr& params,
        boost::asio::yield_context& yc,
-       bool& hasStartedStreaming
+       HttpServerConnection& server
 )
 {
        namespace http = boost::beast::http;
index 346340d8180bc1052dcc90cadffe198e62ed2cb2..e1fe983149f948d9af24ce39aab4581f4893f988 100644 (file)
@@ -21,7 +21,7 @@ public:
                boost::beast::http::response<boost::beast::http::string_body>& response,
                const Dictionary::Ptr& params,
                boost::asio::yield_context& yc,
-               bool& hasStartedStreaming
+               HttpServerConnection& server
        ) override;
 };
 
index 2150903a1fa394bf4fcbec873256398246d86cc9..3f360fe30e64d50481b7e1041d91ff6061f04e97 100644 (file)
@@ -20,7 +20,7 @@ bool ModifyObjectHandler::HandleRequest(
        boost::beast::http::response<boost::beast::http::string_body>& response,
        const Dictionary::Ptr& params,
        boost::asio::yield_context& yc,
-       bool& hasStartedStreaming
+       HttpServerConnection& server
 )
 {
        namespace http = boost::beast::http;
index c9bb216124875a60b0281a474e567ad1c09901ce..f4693013f30e70267e21ce9809ff2c48fb8951c5 100644 (file)
@@ -21,7 +21,7 @@ public:
                boost::beast::http::response<boost::beast::http::string_body>& response,
                const Dictionary::Ptr& params,
                boost::asio::yield_context& yc,
-               bool& hasStartedStreaming
+               HttpServerConnection& server
        ) override;
 };
 
index 2d9b798458456925fea96e1cdf535b21e09ed2e5..3f827037c37414ee6b02bdfe3e6653e4bc49e8ab 100644 (file)
@@ -95,7 +95,7 @@ bool ObjectQueryHandler::HandleRequest(
        boost::beast::http::response<boost::beast::http::string_body>& response,
        const Dictionary::Ptr& params,
        boost::asio::yield_context& yc,
-       bool& hasStartedStreaming
+       HttpServerConnection& server
 )
 {
        namespace http = boost::beast::http;
index c35ff4066ce9d2ad84202089b7dcc439abf5d00b..691b2cfcf210ca61ebf11505db0b3efa3d5500e8 100644 (file)
@@ -21,7 +21,7 @@ public:
                boost::beast::http::response<boost::beast::http::string_body>& response,
                const Dictionary::Ptr& params,
                boost::asio::yield_context& yc,
-               bool& hasStartedStreaming
+               HttpServerConnection& server
        ) override;
 
 private:
index cc725e4f42158112a62e1d3e09b2797f3e9f2f80..1f3f61899f04fa056fa3de55df0df2a96bf4afd6 100644 (file)
@@ -76,7 +76,7 @@ bool StatusHandler::HandleRequest(
        boost::beast::http::response<boost::beast::http::string_body>& response,
        const Dictionary::Ptr& params,
        boost::asio::yield_context& yc,
-       bool& hasStartedStreaming
+       HttpServerConnection& server
 )
 {
        namespace http = boost::beast::http;
index 36f5efcf15cd2521934132eba2c7ea25d9b1a295..c722ab3e2ee36b4da1e5fc4b3c68ac462142cb9c 100644 (file)
@@ -21,7 +21,7 @@ public:
                boost::beast::http::response<boost::beast::http::string_body>& response,
                const Dictionary::Ptr& params,
                boost::asio::yield_context& yc,
-               bool& hasStartedStreaming
+               HttpServerConnection& server
        ) override;
 };
 
index 38a2255401131fabb5ad7f9d0af981acce4c8344..e70dafb6501030f2a38fc5d3492d5c2ba076e074 100644 (file)
@@ -83,7 +83,7 @@ bool TemplateQueryHandler::HandleRequest(
        boost::beast::http::response<boost::beast::http::string_body>& response,
        const Dictionary::Ptr& params,
        boost::asio::yield_context& yc,
-       bool& hasStartedStreaming
+       HttpServerConnection& server
 )
 {
        namespace http = boost::beast::http;
index e9dec8896d4b68fa4cb5daf78bdc3e215e5aa2b6..503bc8560603015d560a276002b9b39668349ccc 100644 (file)
@@ -21,7 +21,7 @@ public:
                boost::beast::http::response<boost::beast::http::string_body>& response,
                const Dictionary::Ptr& params,
                boost::asio::yield_context& yc,
-               bool& hasStartedStreaming
+               HttpServerConnection& server
        ) override;
 };
 
index 07711377473924989d9031e310f447d2354dcb9a..4e82653986ca07ca1c84c2158c306c92ce3daa52 100644 (file)
@@ -54,7 +54,7 @@ bool TypeQueryHandler::HandleRequest(
        boost::beast::http::response<boost::beast::http::string_body>& response,
        const Dictionary::Ptr& params,
        boost::asio::yield_context& yc,
-       bool& hasStartedStreaming
+       HttpServerConnection& server
 )
 {
        namespace http = boost::beast::http;
index 84c04185d1e3aa6f398b917e59ffa79d7f064742..5489cb232d272b17ae88dbf15799c777b26c64ce 100644 (file)
@@ -21,7 +21,7 @@ public:
                boost::beast::http::response<boost::beast::http::string_body>& response,
                const Dictionary::Ptr& params,
                boost::asio::yield_context& yc,
-               bool& hasStartedStreaming
+               HttpServerConnection& server
        ) override;
 };
 
index 05b503783d96e9f11b96d140d271b70a196e78ce..aef896e6fbb2282bf4320ef3b62fa8602455baa1 100644 (file)
@@ -64,7 +64,7 @@ bool VariableQueryHandler::HandleRequest(
        boost::beast::http::response<boost::beast::http::string_body>& response,
        const Dictionary::Ptr& params,
        boost::asio::yield_context& yc,
-       bool& hasStartedStreaming
+       HttpServerConnection& server
 )
 {
        namespace http = boost::beast::http;
index ecc71a96aa08318f3ea6946bca37491a1e8cf062..48e73be356d46dd16d10e58258acc7b5e3bbaa6b 100644 (file)
@@ -21,7 +21,7 @@ public:
                boost::beast::http::response<boost::beast::http::string_body>& response,
                const Dictionary::Ptr& params,
                boost::asio::yield_context& yc,
-               bool& hasStartedStreaming
+               HttpServerConnection& server
        ) override;
 };