2016-06-12 22:27:24 +02:00
|
|
|
#ifndef QTHTTPREPLY_H
|
|
|
|
#define QTHTTPREPLY_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QHash>
|
|
|
|
#include <QList>
|
|
|
|
|
|
|
|
class QtHttpServer;
|
|
|
|
|
2019-07-21 15:03:50 +02:00
|
|
|
class QtHttpReply : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_ENUMS (StatusCode)
|
2016-06-12 22:27:24 +02:00
|
|
|
|
|
|
|
public:
|
2019-07-21 15:03:50 +02:00
|
|
|
explicit QtHttpReply (QtHttpServer * parent);
|
|
|
|
|
|
|
|
enum StatusCode
|
|
|
|
{
|
|
|
|
Ok = 200,
|
|
|
|
SeeOther = 303,
|
|
|
|
BadRequest = 400,
|
|
|
|
Forbidden = 403,
|
|
|
|
NotFound = 404,
|
|
|
|
MethodNotAllowed = 405,
|
|
|
|
InternalError = 500,
|
|
|
|
NotImplemented = 501,
|
|
|
|
BadGateway = 502,
|
|
|
|
ServiceUnavailable = 503,
|
|
|
|
};
|
|
|
|
|
|
|
|
int getRawDataSize (void) const { return m_data.size(); };
|
|
|
|
bool useChunked (void) const { return m_useChunked; };
|
|
|
|
StatusCode getStatusCode (void) const { return m_statusCode; };
|
|
|
|
QByteArray getRawData (void) const { return m_data; };
|
|
|
|
QList<QByteArray> getHeadersList (void) const { return m_headersHash.keys (); };
|
|
|
|
|
|
|
|
QByteArray getHeader (const QByteArray & header) const
|
|
|
|
{
|
|
|
|
return m_headersHash.value (header, QByteArray ());
|
|
|
|
};
|
|
|
|
|
|
|
|
static const QByteArray getStatusTextForCode (StatusCode statusCode);
|
2016-06-12 22:27:24 +02:00
|
|
|
|
|
|
|
public slots:
|
2019-07-21 15:03:50 +02:00
|
|
|
void setUseChunked (bool chunked = false) { m_useChunked = chunked; };
|
|
|
|
void setStatusCode (StatusCode statusCode) { m_statusCode = statusCode; };
|
|
|
|
void appendRawData (const QByteArray & data) { m_data.append(data); };
|
|
|
|
void addHeader (const QByteArray & header, const QByteArray & value);
|
|
|
|
void resetRawData (void) { m_data.clear (); };
|
2016-06-12 22:27:24 +02:00
|
|
|
|
|
|
|
signals:
|
2019-07-21 15:03:50 +02:00
|
|
|
void requestSendHeaders (void);
|
|
|
|
void requestSendData (void);
|
2016-06-12 22:27:24 +02:00
|
|
|
|
|
|
|
private:
|
2019-07-21 15:03:50 +02:00
|
|
|
bool m_useChunked;
|
|
|
|
StatusCode m_statusCode;
|
|
|
|
QByteArray m_data;
|
|
|
|
QtHttpServer * m_serverHandle;
|
|
|
|
QHash<QByteArray, QByteArray> m_headersHash;
|
2016-06-12 22:27:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // QTHTTPREPLY_H
|