2016-06-12 22:27:24 +02:00
|
|
|
#ifndef QTHTTPCLIENTWRAPPER_H
|
|
|
|
#define QTHTTPCLIENTWRAPPER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
class QTcpSocket;
|
|
|
|
|
|
|
|
class QtHttpRequest;
|
|
|
|
class QtHttpReply;
|
|
|
|
class QtHttpServer;
|
2017-11-20 00:06:45 +01:00
|
|
|
class WebSocketClient;
|
|
|
|
class WebJsonRpc;
|
2016-06-12 22:27:24 +02:00
|
|
|
|
|
|
|
class QtHttpClientWrapper : public QObject {
|
2019-07-12 16:54:26 +02:00
|
|
|
Q_OBJECT
|
2016-06-12 22:27:24 +02:00
|
|
|
|
|
|
|
public:
|
2019-07-12 16:54:26 +02:00
|
|
|
explicit QtHttpClientWrapper (QTcpSocket * sock, const bool& localConnection, QtHttpServer * parent);
|
2016-06-12 22:27:24 +02:00
|
|
|
|
2019-07-12 16:54:26 +02:00
|
|
|
static const char SPACE = ' ';
|
|
|
|
static const char COLON = ':';
|
|
|
|
static const QByteArray & CRLF;
|
2016-06-12 22:27:24 +02:00
|
|
|
|
2019-07-12 16:54:26 +02:00
|
|
|
enum ParsingStatus {
|
|
|
|
ParsingError = -1,
|
|
|
|
AwaitingRequest = 0,
|
|
|
|
AwaitingHeaders = 1,
|
|
|
|
AwaitingContent = 2,
|
|
|
|
RequestParsed = 3
|
|
|
|
};
|
2016-06-12 22:27:24 +02:00
|
|
|
|
2019-07-12 16:54:26 +02:00
|
|
|
QString getGuid (void);
|
2017-11-20 00:06:45 +01:00
|
|
|
/// @brief Wrapper for sendReplyToClient(), handles m_parsingStatus and signal connect
|
|
|
|
void sendToClientWithReply (QtHttpReply * reply);
|
2016-06-12 22:27:24 +02:00
|
|
|
|
2019-09-17 21:33:46 +02:00
|
|
|
///
|
|
|
|
/// @brief close a connection with FORBIDDEN header (used from JsonAPI over HTTP)
|
|
|
|
///
|
|
|
|
void closeConnection();
|
|
|
|
|
2016-06-12 22:27:24 +02:00
|
|
|
private slots:
|
2019-07-12 16:54:26 +02:00
|
|
|
void onClientDataReceived (void);
|
2016-06-12 22:27:24 +02:00
|
|
|
|
|
|
|
protected:
|
2019-07-12 16:54:26 +02:00
|
|
|
ParsingStatus sendReplyToClient (QtHttpReply * reply);
|
2016-06-12 22:27:24 +02:00
|
|
|
|
|
|
|
protected slots:
|
2019-07-12 16:54:26 +02:00
|
|
|
void onReplySendHeadersRequested (void);
|
|
|
|
void onReplySendDataRequested (void);
|
2016-06-12 22:27:24 +02:00
|
|
|
|
|
|
|
private:
|
2019-07-12 16:54:26 +02:00
|
|
|
QString m_guid;
|
|
|
|
ParsingStatus m_parsingStatus;
|
|
|
|
QTcpSocket * m_sockClient;
|
|
|
|
QtHttpRequest * m_currentRequest;
|
|
|
|
QtHttpServer * m_serverHandle;
|
|
|
|
const bool m_localConnection;
|
2019-01-06 19:49:56 +01:00
|
|
|
WebSocketClient * m_websocketClient;
|
|
|
|
WebJsonRpc * m_webJsonRpc;
|
2016-06-12 22:27:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // QTHTTPCLIENTWRAPPER_H
|