Move JSON output functionality to socket.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QTcpSocket>
|
||||
|
||||
#include <QHttpEngine/QHttpParser>
|
||||
@@ -325,6 +326,16 @@ void QHttpSocket::writeError(int statusCode, const QByteArray &statusReason)
|
||||
close();
|
||||
}
|
||||
|
||||
void QHttpSocket::writeJson(const QJsonDocument &document, int statusCode)
|
||||
{
|
||||
QByteArray data = document.toJson();
|
||||
setStatusCode(statusCode);
|
||||
setHeader("Content-Length", QByteArray::number(data.length()));
|
||||
setHeader("Content-Type", "application/json");
|
||||
write(data);
|
||||
close();
|
||||
}
|
||||
|
||||
qint64 QHttpSocket::readData(char *data, qint64 maxlen)
|
||||
{
|
||||
// Ensure the connection is in the correct state for reading data
|
||||
|
||||
@@ -90,15 +90,6 @@ bool QObjectHandler::readJson(QHttpSocket *socket, QJsonDocument &document)
|
||||
return true;
|
||||
}
|
||||
|
||||
void QObjectHandler::writeJson(QHttpSocket *socket, const QJsonDocument &document)
|
||||
{
|
||||
QByteArray data = document.toJson();
|
||||
socket->setHeader("Content-Length", QByteArray::number(data.length()));
|
||||
socket->setHeader("Content-Type", "application/json");
|
||||
socket->write(data);
|
||||
socket->close();
|
||||
}
|
||||
|
||||
void QObjectHandler::process(QHttpSocket *socket, const QString &path)
|
||||
{
|
||||
// Ensure the method has been registered
|
||||
|
||||
Reference in New Issue
Block a user