2016-06-12 22:27:24 +02:00
|
|
|
|
|
|
|
#include "QtHttpReply.h"
|
|
|
|
#include "QtHttpHeader.h"
|
|
|
|
#include "QtHttpServer.h"
|
|
|
|
|
|
|
|
#include <QDateTime>
|
|
|
|
|
|
|
|
QtHttpReply::QtHttpReply (QtHttpServer * parent)
|
2019-07-21 15:03:50 +02:00
|
|
|
: QObject (parent)
|
|
|
|
, m_useChunked (false)
|
|
|
|
, m_statusCode (Ok)
|
|
|
|
, m_data (QByteArray ())
|
|
|
|
, m_serverHandle (parent)
|
2016-06-12 22:27:24 +02:00
|
|
|
{
|
2019-07-21 15:03:50 +02:00
|
|
|
// set some additional headers
|
|
|
|
addHeader (QtHttpHeader::Date, QDateTime::currentDateTimeUtc ().toString ("ddd, dd MMM yyyy hh:mm:ss t").toUtf8 ());
|
|
|
|
addHeader (QtHttpHeader::Server, m_serverHandle->getServerName ().toUtf8 ());
|
2016-06-12 22:27:24 +02:00
|
|
|
}
|
|
|
|
|
2019-07-21 15:03:50 +02:00
|
|
|
const QByteArray QtHttpReply::getStatusTextForCode (QtHttpReply::StatusCode statusCode)
|
|
|
|
{
|
|
|
|
switch (statusCode)
|
|
|
|
{
|
|
|
|
case Ok: return QByteArrayLiteral ("OK.");
|
|
|
|
case BadRequest: return QByteArrayLiteral ("Bad request !");
|
|
|
|
case Forbidden: return QByteArrayLiteral ("Forbidden !");
|
|
|
|
case NotFound: return QByteArrayLiteral ("Not found !");
|
|
|
|
default: return QByteArrayLiteral ("");
|
|
|
|
}
|
2016-06-12 22:27:24 +02:00
|
|
|
}
|
|
|
|
|
2019-07-21 15:03:50 +02:00
|
|
|
void QtHttpReply::addHeader (const QByteArray & header, const QByteArray & value)
|
|
|
|
{
|
|
|
|
QByteArray key = header.trimmed ();
|
2016-06-12 22:27:24 +02:00
|
|
|
|
2019-07-21 15:03:50 +02:00
|
|
|
if (!key.isEmpty ())
|
|
|
|
{
|
|
|
|
m_headersHash.insert (key, value);
|
|
|
|
}
|
2016-06-12 22:27:24 +02:00
|
|
|
}
|