@@ -552,12 +552,12 @@ QVector<FileInfo *> FakePutMultiFileReply::performMultiPart(FileInfo &remoteRoot
552
552
auto onePartBody = onePart.mid (headerEndPosition + 4 , onePart.size () - headerEndPosition - 6 );
553
553
auto onePartHeaders = onePartHeaderPart.split (QStringLiteral (" \r\n " ));
554
554
QMap<QString, QString> allHeaders;
555
- for (auto oneHeader : onePartHeaders) {
555
+ for (const auto & oneHeader : onePartHeaders) {
556
556
auto headerParts = oneHeader.split (QStringLiteral (" : " ));
557
- allHeaders[headerParts.at (0 )] = headerParts.at (1 );
557
+ allHeaders[headerParts.at (0 ). toLower () ] = headerParts.at (1 );
558
558
}
559
- const auto fileName = allHeaders[QStringLiteral (" X-File-Path " )];
560
- const auto modtime = allHeaders[QByteArrayLiteral (" X-File-Mtime " )].toLongLong ();
559
+ const auto fileName = allHeaders[QStringLiteral (" x-file-path " )];
560
+ const auto modtime = allHeaders[QByteArrayLiteral (" x-file-mtime " )].toLongLong ();
561
561
Q_ASSERT (!fileName.isEmpty ());
562
562
Q_ASSERT (modtime > 0 );
563
563
FileInfo *fileInfo = remoteRootFileInfo.find (fileName);
@@ -568,7 +568,7 @@ QVector<FileInfo *> FakePutMultiFileReply::performMultiPart(FileInfo &remoteRoot
568
568
// Assume that the file is filled with the same character
569
569
fileInfo = remoteRootFileInfo.create (fileName, onePartBody.size (), onePartBody.at (0 ).toLatin1 ());
570
570
}
571
- fileInfo->lastModified = OCC::Utility::qDateTimeFromTime_t (request.rawHeader (" X-OC-Mtime " ).toLongLong ());
571
+ fileInfo->lastModified = OCC::Utility::qDateTimeFromTime_t (request.rawHeader (" x-oc-mtime " ).toLongLong ());
572
572
remoteRootFileInfo.find (fileName, /* invalidateEtags=*/ true );
573
573
result.push_back (fileInfo);
574
574
}
@@ -1052,13 +1052,13 @@ QJsonObject FakeQNAM::forEachReplyPart(QIODevice *outgoingData,
1052
1052
QMap<QString, QByteArray> allHeaders;
1053
1053
for (const auto &oneHeader : qAsConst (onePartHeaders)) {
1054
1054
auto headerParts = oneHeader.split (QStringLiteral (" : " ));
1055
- allHeaders[headerParts.at (0 )] = headerParts.at (1 ).toLatin1 ();
1055
+ allHeaders[headerParts.at (0 ). toLower () ] = headerParts.at (1 ).toLatin1 ();
1056
1056
}
1057
1057
1058
1058
auto reply = replyFunction (allHeaders);
1059
1059
if (reply.contains (QStringLiteral (" error" )) &&
1060
1060
reply.contains (QStringLiteral (" etag" ))) {
1061
- fullReply.insert (allHeaders[QStringLiteral (" X-File-Path " )], reply);
1061
+ fullReply.insert (allHeaders[QStringLiteral (" x-file-path " )], reply);
1062
1062
}
1063
1063
}
1064
1064
@@ -1413,3 +1413,46 @@ FakeFileLockReply::FakeFileLockReply(FileInfo &remoteRootFileInfo,
1413
1413
xml.writeEndElement (); // prop
1414
1414
xml.writeEndDocument ();
1415
1415
}
1416
+
1417
+ FakeJsonReply::FakeJsonReply (QNetworkAccessManager::Operation op,
1418
+ const QNetworkRequest &request,
1419
+ QObject *parent,
1420
+ int httpReturnCode,
1421
+ const QJsonDocument &reply)
1422
+ : FakeReply{parent}
1423
+ , _body{reply.toJson ()}
1424
+ {
1425
+ setRequest (request);
1426
+ setUrl (request.url ());
1427
+ setOperation (op);
1428
+ open (QIODevice::ReadOnly);
1429
+ setAttribute (QNetworkRequest::HttpStatusCodeAttribute, httpReturnCode);
1430
+ QMetaObject::invokeMethod (this , &FakeJsonReply::respond, Qt::QueuedConnection);
1431
+ }
1432
+
1433
+ void FakeJsonReply::respond ()
1434
+ {
1435
+ emit metaDataChanged ();
1436
+ emit readyRead ();
1437
+ // finishing can come strictly after readyRead was called
1438
+ QTimer::singleShot (5 , this , &FakeJsonReply::slotSetFinished);
1439
+ }
1440
+
1441
+ void FakeJsonReply::slotSetFinished ()
1442
+ {
1443
+ setFinished (true );
1444
+ emit finished ();
1445
+ }
1446
+
1447
+ qint64 FakeJsonReply::readData (char *buf, qint64 max)
1448
+ {
1449
+ max = qMin<qint64>(max, _body.size ());
1450
+ memcpy (buf, _body.constData (), max);
1451
+ _body = _body.mid (max);
1452
+ return max;
1453
+ }
1454
+
1455
+ qint64 FakeJsonReply::bytesAvailable () const
1456
+ {
1457
+ return _body.size ();
1458
+ }
0 commit comments