2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2014-04-12 04:21:09 +02:00
|
|
|
|
2015-08-29 01:16:16 +02:00
|
|
|
#ifndef HTTPCLIENTCONNECTION_H
|
|
|
|
#define HTTPCLIENTCONNECTION_H
|
2014-04-12 04:21:09 +02:00
|
|
|
|
2015-06-22 11:11:21 +02:00
|
|
|
#include "remote/httprequest.hpp"
|
2015-08-29 01:16:16 +02:00
|
|
|
#include "remote/httpresponse.hpp"
|
|
|
|
#include "base/stream.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "base/timer.hpp"
|
2015-08-29 01:16:16 +02:00
|
|
|
#include <deque>
|
2014-04-12 04:21:09 +02:00
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
2015-08-29 01:16:16 +02:00
|
|
|
* An HTTP client connection.
|
2014-04-12 04:21:09 +02:00
|
|
|
*
|
2014-05-03 20:02:22 +02:00
|
|
|
* @ingroup remote
|
2014-04-12 04:21:09 +02:00
|
|
|
*/
|
2018-01-04 06:11:04 +01:00
|
|
|
class HttpClientConnection final : public Object
|
2014-04-12 04:21:09 +02:00
|
|
|
{
|
|
|
|
public:
|
2015-08-29 01:16:16 +02:00
|
|
|
DECLARE_PTR_TYPEDEFS(HttpClientConnection);
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2018-01-04 08:54:18 +01:00
|
|
|
HttpClientConnection(String host, String port, bool tls = true);
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void Start();
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
Stream::Ptr GetStream() const;
|
|
|
|
String GetHost() const;
|
|
|
|
String GetPort() const;
|
|
|
|
bool GetTls() const;
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void Disconnect();
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
std::shared_ptr<HttpRequest> NewRequest();
|
2015-08-29 01:16:16 +02:00
|
|
|
|
2017-11-21 11:52:55 +01:00
|
|
|
typedef std::function<void(HttpRequest&, HttpResponse&)> HttpCompletionCallback;
|
2017-11-21 13:20:55 +01:00
|
|
|
void SubmitRequest(const std::shared_ptr<HttpRequest>& request, const HttpCompletionCallback& callback);
|
2015-08-29 01:16:16 +02:00
|
|
|
|
2014-04-12 04:21:09 +02:00
|
|
|
private:
|
2015-08-29 01:16:16 +02:00
|
|
|
String m_Host;
|
|
|
|
String m_Port;
|
|
|
|
bool m_Tls;
|
|
|
|
Stream::Ptr m_Stream;
|
2017-11-21 13:20:55 +01:00
|
|
|
std::deque<std::pair<std::shared_ptr<HttpRequest>, HttpCompletionCallback> > m_Requests;
|
|
|
|
std::shared_ptr<HttpResponse> m_CurrentResponse;
|
2015-06-24 09:44:59 +02:00
|
|
|
boost::mutex m_DataHandlerMutex;
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-02-14 16:34:36 +01:00
|
|
|
StreamReadContext m_Context;
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void Reconnect();
|
|
|
|
bool ProcessMessage();
|
2015-09-29 10:31:16 +02:00
|
|
|
void DataAvailableHandler(const Stream::Ptr& stream);
|
2015-02-26 12:41:47 +01:00
|
|
|
|
2015-06-22 11:11:21 +02:00
|
|
|
void ProcessMessageAsync(HttpRequest& request);
|
2014-04-12 04:21:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-29 01:16:16 +02:00
|
|
|
#endif /* HTTPCLIENTCONNECTION_H */
|