@@ -300,21 +300,32 @@ QPair<QString, QHash<QString, QString>> WebSocketServerService::parseHttpRequest
300300 return {method, queryParams};
301301}
302302
303+ QString WebSocketServerService::httpResponse (int statusCode, const QByteArray &body) {
304+ return httpResponse (statusCode, body, QLatin1String (" OK" ));
305+ }
306+
307+ QString WebSocketServerService::httpResponse (int statusCode, const QByteArray &body,
308+ const QString &statusText) {
309+ return httpResponse (statusCode, body, statusText,
310+ QLatin1String (" application/json; charset=utf-8" ));
311+ }
312+
303313QString WebSocketServerService::httpResponse (int statusCode, const QByteArray &body,
304314 const QString &statusText,
305315 const QString &contentType) {
306- return QStringLiteral (
307- " HTTP/1.1 %1 %2\r\n "
308- " Content-Type: %3\r\n "
309- " Content-Length: %4\r\n "
310- " Access-Control-Allow-Origin: *\r\n "
311- " Access-Control-Allow-Methods: GET, OPTIONS\r\n "
312- " Access-Control-Allow-Headers: Content-Type\r\n "
313- " Cache-Control: no-store\r\n "
314- " Connection: close\r\n "
315- " \r\n %5" )
316- .arg (QString::number (statusCode), statusText, contentType, QString::number (body.size ()),
317- QString::fromUtf8 (body));
316+ const QString responseTemplate = QString::fromLatin1 (
317+ " HTTP/1.1 %1 %2\r\n "
318+ " Content-Type: %3\r\n "
319+ " Content-Length: %4\r\n "
320+ " Access-Control-Allow-Origin: *\r\n "
321+ " Access-Control-Allow-Methods: GET, OPTIONS\r\n "
322+ " Access-Control-Allow-Headers: Content-Type\r\n "
323+ " Cache-Control: no-store\r\n "
324+ " Connection: close\r\n "
325+ " \r\n %5" );
326+
327+ return responseTemplate.arg (QString::number (statusCode), statusText, contentType,
328+ QString::number (body.size ()), QString::fromUtf8 (body));
318329}
319330
320331QVector<Bookmark> WebSocketServerService::getBookmarksForSuggestions () {
0 commit comments