19 void writeHeader(
const char *field,
const QString &value);
20 void write(
const QByteArray &data);
22 void setHeader(
const QString &field,
const QString &value);
41 : m_connection(nullptr),
42 m_headerWritten(false),
43 m_sentConnectionHeader(false),
44 m_sentContentLengthHeader(false),
45 m_sentTransferEncodingHeader(false),
49 m_useChunkedEncoding(false),
65 if(
name.compare(
"connection", Qt::CaseInsensitive) == 0)
68 if(value.compare(
"close", Qt::CaseInsensitive) == 0)
77 else if(
name.compare(
"transfer-encoding", Qt::CaseInsensitive) == 0)
80 if(value.compare(
"chunked", Qt::CaseInsensitive) == 0)
85 else if(
name.compare(
"content-length", Qt::CaseInsensitive) == 0)
89 else if(
name.compare(
"date", Qt::CaseInsensitive) == 0)
127 QLocale::c().
toString(QDateTime::currentDateTimeUtc(),
128 "ddd, dd MMM yyyy hh:mm:ss") +
" GMT");
136 qWarning() <<
"QHttpResponse::writeHead() Cannot write headers after response has finished.";
141 qWarning() <<
"QHttpResponse::writeHead() Already called once for this response.";
163 qWarning() <<
"QHttpResponse::writeHeader() Cannot write headers after response has finished.";
171 qWarning() <<
"QHttpResponse::write() Cannot write body after response has finished.";
177 qWarning() <<
"QHttpResponse::write() You must call writeHead() before writing body data.";
192 qWarning() <<
"QHttpResponse::setHeader() Cannot set headers after response has finished.";
203 d->m_connection = connection;
210 d->setHeader(field, value);
216 d->writeHead(status);
234 d->m_connection->flush();
240 d->m_connection->waitForBytesWritten();
248 qWarning() <<
"QHttpResponse::end() Cannot write end after response has finished.";
252 if(data.length() > 0)
256 d->m_finished =
true;
267 d->m_finished =
true;
275 d->m_keepAlive = alive;
#define TTKStaticCast(x, y)
The class of the http response.
The class of the http connection.
void write(const QByteArray &data)
Writes a block of data to the client.
void flush()
Flushes the written data to the client.
void setKeepAlive(bool alive)
void end(const QByteArray &data="")
End/finish the response.
bool m_useChunkedEncoding
void writeHeader(const char *field, const QString &value)
bool m_sentTransferEncodingHeader
void waitForBytesWritten()
Waiting for bytes to be written. See QAbstractSocket::waitForBytesWritten in the Qt documentation...
QHash< int, QString > STATUS_CODES
Maps status codes to string reason phrases.
StatusCode
HTTP status code.
QHttpConnection * m_connection
void write(const QByteArray &data)
void writeHead(int status)
void write(const QByteArray &data)
QHttpResponse(QHttpConnection *connection)
QHash< QString, QString > HeaderHash
The class of the http response private.
bool m_sentContentLengthHeader
TTK_MODULE_EXPORT QString toString(Record type)
void done()
Emitted when the response is finished.
void setHeader(const QString &field, const QString &value)
Sets a response header field to value.
#define TTK_INIT_PRIVATE(Class)
void setHeader(const QString &field, const QString &value)
bool m_sentConnectionHeader
void allBytesWritten()
Emitted when all the data has been sent.
The class of the ttk private base.
void writeHead(int statusCode)
Writes the header section of the response using status as the response status code.