Add "DELETE" support to XMLHttpRequest
authorAaron Kennedy <aaron.kennedy@nokia.com>
Mon, 20 Jun 2011 05:22:08 +0000 (15:22 +1000)
committerAaron Kennedy <aaron.kennedy@nokia.com>
Mon, 20 Jun 2011 05:31:54 +0000 (15:31 +1000)
src/declarative/qml/qdeclarativexmlhttprequest.cpp
tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData.qml
tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_DELETE.expect [new file with mode: 0644]
tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_HEAD.expect [moved from tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_PUT.expect with 100% similarity]
tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp

index 83b7d17..f74995b 100644 (file)
@@ -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");
 
 
index c98555c..442932b 100644 (file)
@@ -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 (file)
index 0000000..b2d177a
--- /dev/null
@@ -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
+
index de16cf4..aad68c5 100644 (file)
@@ -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