Add ability to modify status code.

This commit is contained in:
Nathan Osman
2016-10-04 19:51:48 -07:00
parent 287edf9825
commit b39b18be6c
4 changed files with 28 additions and 0 deletions

View File

@@ -49,6 +49,8 @@ void QObjectHandlerPrivate::invokeSlot(QHttpSocket *socket, int index, const QVa
QGenericArgument secondArgument;
QVariantMap parameters;
statusCode = QHttpSocket::OK;
// If this is a POST request, then decode the request body
if (socket->method() == MethodPOST) {
@@ -78,6 +80,7 @@ void QObjectHandlerPrivate::invokeSlot(QHttpSocket *socket, int index, const QVa
// Convert the return value to JSON and write it to the socket
QByteArray data = QJsonDocument(QJsonObject::fromVariantMap(retVal)).toJson();
socket->setStatusCode(statusCode);
socket->setHeader("Content-Length", QByteArray::number(data.length()));
socket->setHeader("Content-Type", "application/json");
socket->write(data);
@@ -146,3 +149,8 @@ void QObjectHandler::process(QHttpSocket *socket, const QString &path)
});
}
}
void QObjectHandler::setStatusCode(int statusCode)
{
d->statusCode = statusCode;
}