2016-06-12 22:27:24 +02:00
|
|
|
|
|
|
|
#include "QtHttpRequest.h"
|
|
|
|
#include "QtHttpHeader.h"
|
|
|
|
#include "QtHttpServer.h"
|
|
|
|
|
2017-01-14 19:04:58 +01:00
|
|
|
QtHttpRequest::QtHttpRequest (QtHttpClientWrapper * client, QtHttpServer * parent)
|
2016-06-12 22:27:24 +02:00
|
|
|
: QObject (parent)
|
|
|
|
, m_url (QUrl ())
|
|
|
|
, m_command (QString ())
|
|
|
|
, m_data (QByteArray ())
|
|
|
|
, m_serverHandle (parent)
|
2017-01-14 19:04:58 +01:00
|
|
|
, m_clientHandle (client)
|
|
|
|
, m_postData (QtHttpPostData())
|
2016-06-12 22:27:24 +02:00
|
|
|
{
|
|
|
|
// set some additional headers
|
|
|
|
addHeader (QtHttpHeader::ContentLength, QByteArrayLiteral ("0"));
|
|
|
|
addHeader (QtHttpHeader::Connection, QByteArrayLiteral ("Keep-Alive"));
|
|
|
|
}
|
|
|
|
|
|
|
|
QUrl QtHttpRequest::getUrl (void) const {
|
|
|
|
return m_url;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString QtHttpRequest::getCommand (void) const {
|
|
|
|
return m_command;
|
|
|
|
}
|
|
|
|
|
2016-06-19 00:56:47 +02:00
|
|
|
QtHttpRequest::ClientInfo QtHttpRequest::getClientInfo (void) const {
|
|
|
|
return m_clientInfo;
|
|
|
|
}
|
|
|
|
|
2016-06-12 22:27:24 +02:00
|
|
|
int QtHttpRequest::getRawDataSize (void) const {
|
|
|
|
return m_data.size ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QByteArray QtHttpRequest::getRawData (void) const {
|
|
|
|
return m_data;
|
|
|
|
}
|
|
|
|
|
2017-01-14 19:04:58 +01:00
|
|
|
QtHttpPostData QtHttpRequest::getPostData (void) const {
|
|
|
|
return m_postData;
|
|
|
|
}
|
|
|
|
|
2016-06-12 22:27:24 +02:00
|
|
|
QList<QByteArray> QtHttpRequest::getHeadersList (void) const {
|
|
|
|
return m_headersHash.keys ();
|
|
|
|
}
|
|
|
|
|
2017-01-14 19:04:58 +01:00
|
|
|
QtHttpClientWrapper * QtHttpRequest::getClient (void) const {
|
|
|
|
return m_clientHandle;
|
|
|
|
}
|
|
|
|
|
2016-06-12 22:27:24 +02:00
|
|
|
QByteArray QtHttpRequest::getHeader (const QByteArray & header) const {
|
|
|
|
return m_headersHash.value (header, QByteArray ());
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtHttpRequest::setUrl (const QUrl & url) {
|
|
|
|
m_url = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtHttpRequest::setCommand (const QString & command) {
|
|
|
|
m_command = command;
|
|
|
|
}
|
|
|
|
|
2016-06-19 00:56:47 +02:00
|
|
|
void QtHttpRequest::setClientInfo (const QHostAddress & server, const QHostAddress & client) {
|
|
|
|
m_clientInfo.serverAddress = server;
|
|
|
|
m_clientInfo.clientAddress = client;
|
|
|
|
}
|
|
|
|
|
2016-06-12 22:27:24 +02:00
|
|
|
void QtHttpRequest::addHeader (const QByteArray & header, const QByteArray & value) {
|
|
|
|
QByteArray key = header.trimmed ();
|
|
|
|
if (!key.isEmpty ()) {
|
|
|
|
m_headersHash.insert (key, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtHttpRequest::appendRawData (const QByteArray & data) {
|
|
|
|
m_data.append (data);
|
|
|
|
}
|
2017-01-14 19:04:58 +01:00
|
|
|
|
|
|
|
void QtHttpRequest::setPostData (const QtHttpPostData & data) {
|
|
|
|
m_postData = data;
|
|
|
|
}
|