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;
boost::beast::http::response<boost::beast::http::string_body>& response,
const Dictionary::Ptr& params,
boost::asio::yield_context& yc,
- bool& hasStartedStreaming
+ HttpServerConnection& server
) override;
};
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;
boost::beast::http::response<boost::beast::http::string_body>& response,
const Dictionary::Ptr& params,
boost::asio::yield_context& yc,
- bool& hasStartedStreaming
+ HttpServerConnection& server
) override;
};
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;
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:
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;
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:
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;
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);
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;
boost::beast::http::response<boost::beast::http::string_body>& response,
const Dictionary::Ptr& params,
boost::asio::yield_context& yc,
- bool& hasStartedStreaming
+ HttpServerConnection& server
) override;
};
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;
boost::beast::http::response<boost::beast::http::string_body>& response,
const Dictionary::Ptr& params,
boost::asio::yield_context& yc,
- bool& hasStartedStreaming
+ HttpServerConnection& server
) override;
};
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;
EventQueue::UnregisterIfUnused(queueName, queue);
});
- hasStartedStreaming = true;
+ server.StartStreaming();
response.result(http::status::ok);
response.set(http::field::content_type, "application/json");
boost::beast::http::response<boost::beast::http::string_body>& response,
const Dictionary::Ptr& params,
boost::asio::yield_context& yc,
- bool& hasStartedStreaming
+ HttpServerConnection& server
) override;
};
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;
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;
}
#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"
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);
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:
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);
});
}
+void HttpServerConnection::StartStreaming()
+{
+ m_HasStartedStreaming = true;
+}
+
static inline
bool EnsureValidHeaders(
AsioTlsStream& stream,
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;
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;
}
void Start();
void Disconnect();
+ void StartStreaming();
private:
ApiUser::Ptr m_ApiUser;
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);
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;
boost::beast::http::response<boost::beast::http::string_body>& response,
const Dictionary::Ptr& params,
boost::asio::yield_context& yc,
- bool& hasStartedStreaming
+ HttpServerConnection& server
) override;
};
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;
boost::beast::http::response<boost::beast::http::string_body>& response,
const Dictionary::Ptr& params,
boost::asio::yield_context& yc,
- bool& hasStartedStreaming
+ HttpServerConnection& server
) override;
};
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;
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:
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;
boost::beast::http::response<boost::beast::http::string_body>& response,
const Dictionary::Ptr& params,
boost::asio::yield_context& yc,
- bool& hasStartedStreaming
+ HttpServerConnection& server
) override;
};
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;
boost::beast::http::response<boost::beast::http::string_body>& response,
const Dictionary::Ptr& params,
boost::asio::yield_context& yc,
- bool& hasStartedStreaming
+ HttpServerConnection& server
) override;
};
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;
boost::beast::http::response<boost::beast::http::string_body>& response,
const Dictionary::Ptr& params,
boost::asio::yield_context& yc,
- bool& hasStartedStreaming
+ HttpServerConnection& server
) override;
};
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;
boost::beast::http::response<boost::beast::http::string_body>& response,
const Dictionary::Ptr& params,
boost::asio::yield_context& yc,
- bool& hasStartedStreaming
+ HttpServerConnection& server
) override;
};