diff options
author | Bea Lam <bea.lam@nokia.com> | 2011-07-21 15:10:30 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-07-26 01:00:09 +0200 |
commit | 38ddc64ec988d3b4668cbbedfc377cab309a08bb (patch) | |
tree | 5c53d462585f15961fce923e99fbc3a61c60f044 | |
parent | 087619b4a941e7f64772cc01a6cdf1213b640270 (diff) |
Don't error if response results in UnknownContentError
XMLHttpRequest specs state that only 'network errors' should result
in a request error, and a HTTP response like 400 Bad Request (which
results in QNetworkReply::UnknownContentError) is an indication of the
HTTP server response rather than a network error.
Task-number: QTBUG-20146
Change-Id: I10c132788200e15b0362da839689a0bb3c2b4a0d
Reviewed-on: http://codereview.qt.nokia.com/1915
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
4 files changed, 10 insertions, 2 deletions
diff --git a/src/declarative/qml/qdeclarativexmlhttprequest.cpp b/src/declarative/qml/qdeclarativexmlhttprequest.cpp index 33875fef88..5a7aa0a003 100644 --- a/src/declarative/qml/qdeclarativexmlhttprequest.cpp +++ b/src/declarative/qml/qdeclarativexmlhttprequest.cpp @@ -1332,7 +1332,8 @@ void QDeclarativeXMLHttpRequest::error(QNetworkReply::NetworkError error) error == QNetworkReply::ContentOperationNotPermittedError || error == QNetworkReply::ContentNotFoundError || error == QNetworkReply::AuthenticationRequiredError || - error == QNetworkReply::ContentReSendError) { + error == QNetworkReply::ContentReSendError || + error == QNetworkReply::UnknownContentError) { m_state = Loading; v8::TryCatch tc; dispatchCallback(m_me); diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/data/status.400.reply b/tests/auto/declarative/qdeclarativexmlhttprequest/data/status.400.reply new file mode 100644 index 0000000000..e3f6944173 --- /dev/null +++ b/tests/auto/declarative/qdeclarativexmlhttprequest/data/status.400.reply @@ -0,0 +1,4 @@ +HTTP/1.0 400 Bad request +Connection: close +Content-type: text/html; charset=UTF-8 + diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/data/status.qml b/tests/auto/declarative/qdeclarativexmlhttprequest/data/status.qml index 51964570d6..f5e10d79ad 100644 --- a/tests/auto/declarative/qdeclarativexmlhttprequest/data/status.qml +++ b/tests/auto/declarative/qdeclarativexmlhttprequest/data/status.qml @@ -48,7 +48,7 @@ QtObject { if (x.status == expectedStatus) done = true; - if (expectedStatus == 404) { + if (expectedStatus != 200) { dataOK = (x.responseText == ""); } else { dataOK = (x.responseText == "QML Rocks!\n"); diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp index d2b7d5b50e..d640840bcd 100644 --- a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp +++ b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp @@ -843,6 +843,7 @@ void tst_qdeclarativexmlhttprequest::status_data() QTest::newRow("OK") << TEST_FILE("status.200.reply") << 200; QTest::newRow("Not Found") << TEST_FILE("status.404.reply") << 404; + QTest::newRow("Bad Request") << TEST_FILE("status.400.reply") << 400; } void tst_qdeclarativexmlhttprequest::statusText() @@ -883,6 +884,7 @@ void tst_qdeclarativexmlhttprequest::statusText_data() QTest::newRow("OK") << TEST_FILE("status.200.reply") << "OK"; QTest::newRow("Not Found") << TEST_FILE("status.404.reply") << "Document not found"; + QTest::newRow("Bad Request") << TEST_FILE("status.400.reply") << "Bad request"; } void tst_qdeclarativexmlhttprequest::responseText() @@ -926,6 +928,7 @@ void tst_qdeclarativexmlhttprequest::responseText_data() QTest::newRow("OK") << TEST_FILE("status.200.reply") << TEST_FILE("testdocument.html") << "QML Rocks!\n"; QTest::newRow("empty body") << TEST_FILE("status.200.reply") << QUrl() << ""; QTest::newRow("Not Found") << TEST_FILE("status.404.reply") << TEST_FILE("testdocument.html") << ""; + QTest::newRow("Bad Request") << TEST_FILE("status.404.reply") << TEST_FILE("testdocument.html") << ""; } void tst_qdeclarativexmlhttprequest::nonUtf8() |