mirror of
https://github.com/QuasarApp/qthttpserver.git
synced 2025-04-27 10:54:31 +00:00
QHttpServerResponse: use compact mode for json objects
Change-Id: Ia01f2f9a1483b326bc92eda20045f9764616cf66 Reviewed-by: Tasuku Suzuki <tasuku.suzuki@qbc.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
b025906bf7
commit
a8777eb51e
@ -71,7 +71,8 @@ QHttpServerResponse::QHttpServerResponse(const QByteArray &data)
|
||||
}
|
||||
|
||||
QHttpServerResponse::QHttpServerResponse(const QJsonObject &data)
|
||||
: QHttpServerResponse(mimeApplicationJson, QJsonDocument(data).toJson())
|
||||
: QHttpServerResponse(mimeApplicationJson,
|
||||
QJsonDocument(data).toJson(QJsonDocument::Compact))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,8 @@
|
||||
#include <QtCore/qbytearray.h>
|
||||
#include <QtCore/qdatetime.h>
|
||||
#include <QtCore/qmetaobject.h>
|
||||
#include <QtCore/qjsonobject.h>
|
||||
#include <QtCore/qjsonvalue.h>
|
||||
|
||||
#include <QtNetwork/qnetworkaccessmanager.h>
|
||||
#include <QtNetwork/qnetworkreply.h>
|
||||
@ -196,6 +198,13 @@ void tst_QHttpServer::initTestCase()
|
||||
return QHttpServerResponse::fromFile(QFINDTESTDATA(QLatin1String("data/") + file));
|
||||
});
|
||||
|
||||
httpserver.route("/json-object/", [] () {
|
||||
return QJsonObject{
|
||||
{"property", "test"},
|
||||
{"value", 1}
|
||||
};
|
||||
});
|
||||
|
||||
urlBase = QStringLiteral("http://localhost:%1%2").arg(httpserver.listen());
|
||||
}
|
||||
|
||||
@ -360,6 +369,12 @@ void tst_QHttpServer::routeGet_data()
|
||||
<< 200
|
||||
<< "application/json"
|
||||
<< "{ \"key\": \"value\" }";
|
||||
|
||||
QTest::addRow("json-object")
|
||||
<< "/json-object/"
|
||||
<< 200
|
||||
<< "application/json"
|
||||
<< "{\"property\":\"test\",\"value\":1}";
|
||||
}
|
||||
|
||||
void tst_QHttpServer::routeGet()
|
||||
|
Loading…
x
Reference in New Issue
Block a user