From 0eeb925aa5039ffddf8d623f250980fc4c97712e Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 20 Jun 2011 15:22:08 +1000 Subject: [PATCH] Add "DELETE" support to XMLHttpRequest --- src/declarative/qml/qdeclarativexmlhttprequest.cpp | 9 +++++-- .../data/send_ignoreData.qml | 2 +- .../data/send_ignoreData_DELETE.expect | 7 ++++++ .../data/send_ignoreData_HEAD.expect | 7 ++++++ .../data/send_ignoreData_PUT.expect | 7 ------ .../tst_qdeclarativexmlhttprequest.cpp | 23 ++++++++++++++++++- 6 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_DELETE.expect create mode 100644 tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_HEAD.expect delete mode 100644 tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_PUT.expect diff --git a/src/declarative/qml/qdeclarativexmlhttprequest.cpp b/src/declarative/qml/qdeclarativexmlhttprequest.cpp index 83b7d17..f74995b 100644 --- a/src/declarative/qml/qdeclarativexmlhttprequest.cpp +++ b/src/declarative/qml/qdeclarativexmlhttprequest.cpp @@ -1163,10 +1163,12 @@ void QDeclarativeXMLHttpRequest::requestFromUrl(const QUrl &url) m_network = networkAccessManager()->get(request); else if (m_method == QLatin1String("HEAD")) m_network = networkAccessManager()->head(request); - else if(m_method == QLatin1String("POST")) + else if (m_method == QLatin1String("POST")) m_network = networkAccessManager()->post(request, m_data); - else if(m_method == QLatin1String("PUT")) + else if (m_method == QLatin1String("PUT")) m_network = networkAccessManager()->put(request, m_data); + else if (m_method == QLatin1String("DELETE")) + m_network = networkAccessManager()->deleteResource(request); QObject::connect(m_network, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgress(qint64))); @@ -1447,7 +1449,8 @@ static QScriptValue qmlxmlhttprequest_open(QScriptContext *context, QScriptEngin if (method != QLatin1String("GET") && method != QLatin1String("PUT") && method != QLatin1String("HEAD") && - method != QLatin1String("POST")) + method != QLatin1String("POST") && + method != QLatin1String("DELETE")) THROW_DOM(SYNTAX_ERR, "Unsupported HTTP method type"); diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData.qml b/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData.qml index c98555c..442932b 100644 --- a/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData.qml +++ b/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData.qml @@ -14,7 +14,7 @@ QtObject { // Test to the end x.onreadystatechange = function() { if (x.readyState == XMLHttpRequest.DONE) { - if (reqType == "HEAD") + if (reqType == "HEAD" || reqType == "DELETE") dataOK = (x.responseText == ""); else dataOK = (x.responseText == "QML Rocks!\n"); diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_DELETE.expect b/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_DELETE.expect new file mode 100644 index 0000000..b2d177a --- /dev/null +++ b/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_DELETE.expect @@ -0,0 +1,7 @@ +DELETE /testdocument.html HTTP/1.1 +ACCEPT-LANGUAGE: en-US +Connection: Keep-Alive +Accept-Encoding: gzip +User-Agent: Mozilla/5.0 +Host: 127.0.0.1:14445 + diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_HEAD.expect b/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_HEAD.expect new file mode 100644 index 0000000..74a9798 --- /dev/null +++ b/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_HEAD.expect @@ -0,0 +1,7 @@ +HEAD /testdocument.html HTTP/1.1 +ACCEPT-LANGUAGE: en-US +Connection: Keep-Alive +Accept-Encoding: gzip +User-Agent: Mozilla/5.0 +Host: 127.0.0.1:14445 + diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_PUT.expect b/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_PUT.expect deleted file mode 100644 index 74a9798..0000000 --- a/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_PUT.expect +++ /dev/null @@ -1,7 +0,0 @@ -HEAD /testdocument.html HTTP/1.1 -ACCEPT-LANGUAGE: en-US -Connection: Keep-Alive -Accept-Encoding: gzip -User-Agent: Mozilla/5.0 -Host: 127.0.0.1:14445 - diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp index de16cf4..aad68c5 100644 --- a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp +++ b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp @@ -497,7 +497,7 @@ void tst_qdeclarativexmlhttprequest::send_alreadySent() delete object; } -// Test that send for a GET or HEAD ignores data +// Test that sends for GET, HEAD and DELETE ignore data void tst_qdeclarativexmlhttprequest::send_ignoreData() { { @@ -522,7 +522,7 @@ void tst_qdeclarativexmlhttprequest::send_ignoreData() { TestHTTPServer server(SERVER_PORT); QVERIFY(server.isValid()); - QVERIFY(server.wait(TEST_FILE("send_ignoreData_PUT.expect"), + QVERIFY(server.wait(TEST_FILE("send_ignoreData_HEAD.expect"), TEST_FILE("send_ignoreData.reply"), QUrl())); @@ -537,6 +537,25 @@ void tst_qdeclarativexmlhttprequest::send_ignoreData() delete object; } + + { + TestHTTPServer server(SERVER_PORT); + QVERIFY(server.isValid()); + QVERIFY(server.wait(TEST_FILE("send_ignoreData_DELETE.expect"), + TEST_FILE("send_ignoreData.reply"), + QUrl())); + + QDeclarativeComponent component(&engine, TEST_FILE("send_ignoreData.qml")); + QObject *object = component.beginCreate(engine.rootContext()); + QVERIFY(object != 0); + object->setProperty("reqType", "DELETE"); + object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + component.completeCreate(); + + QTRY_VERIFY(object->property("dataOK").toBool() == true); + + delete object; + } } // Test that send()'ing data works -- 1.7.2.5