2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2014-04-12 04:21:09 +02:00
|
|
|
|
2015-06-22 11:11:21 +02:00
|
|
|
#ifndef HTTPREQUEST_H
|
|
|
|
#define HTTPREQUEST_H
|
2014-04-12 04:21:09 +02:00
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "remote/i2-remote.hpp"
|
2015-06-22 11:11:21 +02:00
|
|
|
#include "remote/httpchunkedencoding.hpp"
|
2015-07-16 13:34:05 +02:00
|
|
|
#include "remote/url.hpp"
|
2015-06-22 11:11:21 +02:00
|
|
|
#include "base/stream.hpp"
|
|
|
|
#include "base/fifo.hpp"
|
|
|
|
#include "base/dictionary.hpp"
|
2014-04-12 04:21:09 +02:00
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
2015-06-22 11:11:21 +02:00
|
|
|
enum HttpVersion
|
2014-05-03 20:02:22 +02:00
|
|
|
{
|
2015-06-22 11:11:21 +02:00
|
|
|
HttpVersion10,
|
|
|
|
HttpVersion11
|
2014-05-03 20:02:22 +02:00
|
|
|
};
|
|
|
|
|
2015-06-22 11:11:21 +02:00
|
|
|
enum HttpRequestState
|
|
|
|
{
|
|
|
|
HttpRequestStart,
|
|
|
|
HttpRequestHeaders,
|
2015-08-29 01:16:16 +02:00
|
|
|
HttpRequestBody,
|
|
|
|
HttpRequestEnd
|
2015-06-22 11:11:21 +02:00
|
|
|
};
|
2014-12-09 13:17:27 +01:00
|
|
|
|
2014-04-12 04:21:09 +02:00
|
|
|
/**
|
2015-06-22 11:11:21 +02:00
|
|
|
* An HTTP request.
|
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
|
|
|
*/
|
2017-12-31 07:22:16 +01:00
|
|
|
struct HttpRequest
|
2014-04-12 04:21:09 +02:00
|
|
|
{
|
|
|
|
public:
|
2018-02-01 15:10:28 +01:00
|
|
|
bool CompleteHeaders;
|
2018-02-08 14:54:52 +01:00
|
|
|
bool CompleteHeaderCheck;
|
2018-02-01 15:10:28 +01:00
|
|
|
bool CompleteBody;
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-06-22 11:11:21 +02:00
|
|
|
String RequestMethod;
|
2015-07-09 17:32:19 +02:00
|
|
|
Url::Ptr RequestUrl;
|
2015-06-22 11:11:21 +02:00
|
|
|
HttpVersion ProtocolVersion;
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-06-22 11:11:21 +02:00
|
|
|
Dictionary::Ptr Headers;
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2018-01-04 08:54:18 +01:00
|
|
|
HttpRequest(Stream::Ptr stream);
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2018-02-21 13:22:17 +01:00
|
|
|
bool ParseHeaders(StreamReadContext& src, bool may_wait);
|
2018-02-01 15:10:28 +01:00
|
|
|
bool ParseBody(StreamReadContext& src, bool may_wait);
|
2015-06-22 11:11:21 +02:00
|
|
|
size_t ReadBody(char *data, size_t count);
|
2014-12-09 13:17:27 +01:00
|
|
|
|
2015-08-29 01:16:16 +02:00
|
|
|
void AddHeader(const String& key, const String& value);
|
|
|
|
void WriteBody(const char *data, size_t count);
|
2018-01-04 04:25:35 +01:00
|
|
|
void Finish();
|
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
|
|
|
Stream::Ptr m_Stream;
|
2017-11-21 13:20:55 +01:00
|
|
|
std::shared_ptr<ChunkReadContext> m_ChunkContext;
|
2015-06-22 11:11:21 +02:00
|
|
|
HttpRequestState m_State;
|
|
|
|
FIFO::Ptr m_Body;
|
2015-08-29 01:16:16 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void FinishHeaders();
|
2014-04-12 04:21:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-06-22 11:11:21 +02:00
|
|
|
#endif /* HTTPREQUEST_H */
|