qnetworkreplyfileimpl: set attributes if file was sent
Set status code and status text if file was sent with reply. Change-Id: Ie6acadc5c1d06538449262ffd8486e8de573b931 Task-number: QTBUG-45581 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com> Reviewed-by: Pasi Keränen <pasi.keranen@digia.com> Reviewed-by: Richard J. Moore <rich@kde.org>
This commit is contained in:
parent
af851c290b
commit
a5890fbcd8
@ -36,7 +36,6 @@
|
||||
#include "QtCore/qdatetime.h"
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QDebug>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@ -136,6 +135,7 @@ QNetworkReplyFileImpl::QNetworkReplyFileImpl(QObject *parent, const QNetworkRequ
|
||||
QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection);
|
||||
QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void QNetworkReplyFileImpl::close()
|
||||
{
|
||||
Q_D(QNetworkReplyFileImpl);
|
||||
@ -182,8 +182,11 @@ qint64 QNetworkReplyFileImpl::readData(char *data, qint64 maxlen)
|
||||
d->realFile.close();
|
||||
if (ret == 0 && bytesAvailable() == 0)
|
||||
return -1;
|
||||
else
|
||||
else {
|
||||
setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 200);
|
||||
setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, QLatin1String("OK"));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
1
tests/auto/network/access/qnetworkreply/element.xml
Normal file
1
tests/auto/network/access/qnetworkreply/element.xml
Normal file
@ -0,0 +1 @@
|
||||
<root attr="value" attr2="value2"><person /><fruit /></root>
|
@ -426,6 +426,8 @@ private Q_SLOTS:
|
||||
|
||||
void qtbug28035browserDoesNotLoadQtProjectOrgCorrectly();
|
||||
|
||||
void qtbug45581WrongReplyStatusCode();
|
||||
|
||||
void synchronousRequest_data();
|
||||
void synchronousRequest();
|
||||
#ifndef QT_NO_SSL
|
||||
@ -7256,6 +7258,34 @@ void tst_QNetworkReply::qtbug28035browserDoesNotLoadQtProjectOrgCorrectly() {
|
||||
QCOMPARE(reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute).toBool(), true);
|
||||
}
|
||||
|
||||
void tst_QNetworkReply::qtbug45581WrongReplyStatusCode()
|
||||
{
|
||||
const QUrl url("file:" + testDataDir + "/element.xml");
|
||||
QNetworkRequest request(url);
|
||||
|
||||
QNetworkReplyPtr reply;
|
||||
QSignalSpy finishedSpy(&manager, SIGNAL(finished(QNetworkReply*)));
|
||||
QSignalSpy sslErrorsSpy(&manager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)));
|
||||
RUN_REQUEST(runSimpleRequest(QNetworkAccessManager::GetOperation, request, reply, 0));
|
||||
QVERIFY(reply->isFinished());
|
||||
|
||||
const QByteArray expectedContent =
|
||||
"<root attr=\"value\" attr2=\"value2\">"
|
||||
"<person /><fruit /></root>\n";
|
||||
|
||||
QCOMPARE(reply->readAll(), expectedContent);
|
||||
|
||||
QCOMPARE(finishedSpy.count(), 0);
|
||||
QCOMPARE(sslErrorsSpy.count(), 0);
|
||||
|
||||
QCOMPARE(reply->header(QNetworkRequest::ContentLengthHeader).toLongLong(), expectedContent.size());
|
||||
|
||||
QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200);
|
||||
QCOMPARE(reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString(), QLatin1String("OK"));
|
||||
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
void tst_QNetworkReply::synchronousRequest_data()
|
||||
{
|
||||
QTest::addColumn<QUrl>("url");
|
||||
|
Loading…
x
Reference in New Issue
Block a user