Fix XmlHttpRequest setHeader bug
authorCharles Yin <charles.yin@nokia.com>
Tue, 26 Jul 2011 23:57:37 +0000 (09:57 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 28 Jul 2011 05:12:34 +0000 (07:12 +0200)
Setting XMLHttpRequest raw header makes header name uppercase, the name
should be kept as it is.

Task-number:QTBUG-20472
Change-Id: I8aa8988d6d18d71ee71a7d2f9c3246b20f006f3c
Reviewed-on: http://codereview.qt.nokia.com/2225
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
14 files changed:
src/declarative/qml/qdeclarativexmlhttprequest.cpp
tests/auto/declarative/qdeclarativexmlhttprequest/data/abort.expect
tests/auto/declarative/qdeclarativexmlhttprequest/data/getResponseHeader.expect
tests/auto/declarative/qdeclarativexmlhttprequest/data/open_network.expect
tests/auto/declarative/qdeclarativexmlhttprequest/data/send_data.1.expect
tests/auto/declarative/qdeclarativexmlhttprequest/data/send_data.4.expect
tests/auto/declarative/qdeclarativexmlhttprequest/data/send_data.6.expect
tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_DELETE.expect
tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_GET.expect
tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_HEAD.expect
tests/auto/declarative/qdeclarativexmlhttprequest/data/setRequestHeader.expect
tests/auto/declarative/qdeclarativexmlhttprequest/data/setRequestHeader_caseInsensitive.qml [new file with mode: 0644]
tests/auto/declarative/qdeclarativexmlhttprequest/data/status.expect
tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp

index 5a7aa0a..194a60f 100644 (file)
@@ -1601,7 +1601,7 @@ static v8::Handle<v8::Value> qmlxmlhttprequest_setRequestHeader(const v8::Argume
         nameUpper.startsWith(QLatin1String("SEC-"))) 
         return v8::Undefined();
 
-    r->addHeader(nameUpper, value);
+    r->addHeader(name, value);
 
     return v8::Undefined();
 }
index 3ed1f7f..d6951a8 100644 (file)
@@ -1,5 +1,5 @@
 PUT /testdocument.html HTTP/1.1
-ACCEPT-LANGUAGE: en-US
+Accept-Language: en-US
 Content-Type: text/plain;charset=UTF-8
 Content-Length: 9
 Connection: Keep-Alive
index 4d940c2..cf5830e 100644 (file)
@@ -1,5 +1,5 @@
 GET /testdocument.html HTTP/1.1
-ACCEPT-LANGUAGE: en-US
+Accept-Language: en-US
 Connection: Keep-Alive
 Accept-Encoding: gzip, deflate
 User-Agent: Mozilla/5.0
index 4d940c2..cf5830e 100644 (file)
@@ -1,5 +1,5 @@
 GET /testdocument.html HTTP/1.1
-ACCEPT-LANGUAGE: en-US
+Accept-Language: en-US
 Connection: Keep-Alive
 Accept-Encoding: gzip, deflate
 User-Agent: Mozilla/5.0
index 98dbbdc..9c07d4b 100644 (file)
@@ -1,5 +1,5 @@
 POST /testdocument.html HTTP/1.1
-ACCEPT-LANGUAGE: en-US
+Accept-Language: en-US
 Content-Type: text/plain;charset=UTF-8
 Content-Length: 12
 Connection: Keep-Alive
index 5f71adf..c2aba77 100644 (file)
@@ -1,5 +1,5 @@
 POST /testdocument.html HTTP/1.1
-ACCEPT-LANGUAGE: en-US
+Accept-Language: en-US
 Content-Type: charset=UTF-8;text/plain
 Content-Length: 12
 Connection: Keep-Alive
index 144283a..b09b1bc 100644 (file)
@@ -1,5 +1,5 @@
 PUT /testdocument.html HTTP/1.1
-ACCEPT-LANGUAGE: en-US
+Accept-Language: en-US
 Content-Type: text/plain;charset=UTF-8
 Content-Length: 12
 Connection: Keep-Alive
index cd13443..e7f8e10 100644 (file)
@@ -1,7 +1,7 @@
 GET /testdocument.html HTTP/1.1
-ACCEPT-LANGUAGE: en-US
-TEST-HEADER: value
-TEST-HEADER2: value,value2
+Accept-Language: en-US
+Test-header: value
+Test-header2: value,value2
 Connection: Keep-Alive
 Accept-Encoding: gzip, deflate
 User-Agent: Mozilla/5.0
diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/data/setRequestHeader_caseInsensitive.qml b/tests/auto/declarative/qdeclarativexmlhttprequest/data/setRequestHeader_caseInsensitive.qml
new file mode 100644 (file)
index 0000000..e03f734
--- /dev/null
@@ -0,0 +1,30 @@
+import QtQuick 2.0
+
+QtObject {
+    property string url
+
+    property bool dataOK: false
+
+    Component.onCompleted: {
+        var x = new XMLHttpRequest;
+
+        x.open("GET", url);
+        x.setRequestHeader("Accept-Language","en-US");
+
+        x.setRequestHeader("Test-header", "value");
+        //Setting headers with just different cases
+        //will be treated as the same header, and accepted
+        //as the last setting.
+        x.setRequestHeader("Test-hEADEr2", "value");
+        x.setRequestHeader("Test-header2", "value2");
+
+        // Test to the end
+        x.onreadystatechange = function() {
+            if (x.readyState == XMLHttpRequest.DONE) {
+                dataOK = (x.responseText == "QML Rocks!\n");
+            }
+        }
+
+        x.send();
+    }
+}
index 4d940c2..cf5830e 100644 (file)
@@ -1,5 +1,5 @@
 GET /testdocument.html HTTP/1.1
-ACCEPT-LANGUAGE: en-US
+Accept-Language: en-US
 Connection: Keep-Alive
 Accept-Encoding: gzip, deflate
 User-Agent: Mozilla/5.0
index d640840..51b23c7 100644 (file)
@@ -74,6 +74,7 @@ private slots:
     void open_sync();
     void open_arg_count();
     void setRequestHeader();
+    void setRequestHeader_caseInsensitive();
     void setRequestHeader_unsent();
     void setRequestHeader_illegalName_data();
     void setRequestHeader_illegalName();
@@ -368,6 +369,25 @@ void tst_qdeclarativexmlhttprequest::setRequestHeader()
     delete object;
 }
 
+// Test valid setRequestHeader() calls with different header cases
+void tst_qdeclarativexmlhttprequest::setRequestHeader_caseInsensitive()
+{
+    TestHTTPServer server(SERVER_PORT);
+    QVERIFY(server.isValid());
+    QVERIFY(server.wait(TEST_FILE("setRequestHeader.expect"),
+                        TEST_FILE("setRequestHeader.reply"),
+                        TEST_FILE("testdocument.html")));
+
+    QDeclarativeComponent component(&engine, TEST_FILE("setRequestHeader_caseInsensitive.qml"));
+    QObject *object = component.beginCreate(engine.rootContext());
+    QVERIFY(object != 0);
+    object->setProperty("url", "http://127.0.0.1:14445/testdocument.html");
+    component.completeCreate();
+
+    QTRY_VERIFY(object->property("dataOK").toBool() == true);
+
+    delete object;
+}
 // Test setting headers before open() throws exception
 void tst_qdeclarativexmlhttprequest::setRequestHeader_unsent()
 {