Reviewed by Darin.
authorap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Apr 2006 16:36:35 +0000 (16:36 +0000)
committerap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Apr 2006 16:36:35 +0000 (16:36 +0000)
        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=8099
          REGRESSION: XMLHttpRequest lowercase post requests broken

        Test: http/tests/xmlhttprequest/methods-lower-case.html

        * xml/xmlhttprequest.cpp:
        (WebCore::XMLHttpRequest::open): Uppercase some HTTP method names, to match a Firefox quirk.
        (WebCore::XMLHttpRequest::send): Account for the above change.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@13652 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/xmlhttprequest/methods-lower-case-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/xmlhttprequest/methods-lower-case.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/xml/xmlhttprequest.cpp

index cad44a801d078fcdb71d3c36bf61f7a72840b6ff..db9e7f6f208a1f1349dc4868d261545ff7c9df08 100644 (file)
@@ -1,3 +1,13 @@
+2006-04-03  Alexey Proskuryakov  <ap@nypop.com>
+
+        Reviewed by Darin.
+
+        - test for http://bugzilla.opendarwin.org/show_bug.cgi?id=8099
+          REGRESSION: XMLHttpRequest lowercase post requests broken
+
+        * http/tests/xmlhttprequest/methods-lower-case-expected.txt: Added.
+        * http/tests/xmlhttprequest/methods-lower-case.html: Added.
+
 2006-04-02  Trey Matteson  <trey@usa.net>
 
         Reviewed by Maciej.
diff --git a/LayoutTests/http/tests/xmlhttprequest/methods-lower-case-expected.txt b/LayoutTests/http/tests/xmlhttprequest/methods-lower-case-expected.txt
new file mode 100644 (file)
index 0000000..99e5f5a
--- /dev/null
@@ -0,0 +1,9 @@
+Tests for bug 8099 - XMLHttpRequest lowercase post requests broken.
+
+get(""): GET(undefined bytes), Content-Type: undefined
+post(""): POST(0 bytes), Content-Type: application/xml
+DoIt(""): DoIt(0 bytes), Content-Type: application/xml
+get(""): GET(undefined bytes), Content-Type: undefined
+post(""): POST(0 bytes), Content-Type: application/xml
+DoIt(""): DoIt(0 bytes), Content-Type: application/xml
+
diff --git a/LayoutTests/http/tests/xmlhttprequest/methods-lower-case.html b/LayoutTests/http/tests/xmlhttprequest/methods-lower-case.html
new file mode 100644 (file)
index 0000000..0ceac7b
--- /dev/null
@@ -0,0 +1,71 @@
+<html>
+<body>
+<p>Tests for <a href="http://bugzilla.opendarwin.org/show_bug.cgi?id=8099"> bug 8099</a> - 
+XMLHttpRequest lowercase post requests broken.</p>
+<script>
+    if (window.layoutTestController) {
+        layoutTestController.dumpAsText();
+        layoutTestController.waitUntilDone();
+    }
+    
+    var console_messages = document.createElement("ol");
+    document.body.appendChild(console_messages);
+    
+    function log(message)
+    {
+        var item = document.createElement("li");
+        item.appendChild(document.createTextNode(message));
+        console_messages.appendChild(item);
+    }
+
+    // sync
+    req = new XMLHttpRequest;
+    req.open("get", "methods.cgi", false);
+    req.send("");
+    log('get(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
+
+    req.open("post", "methods.cgi", false);
+    req.send("");
+    log('post(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
+
+    req.open("DoIt", "methods.cgi", false);
+    req.send("");
+    log('DoIt(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
+
+    // async
+    var asyncStep = 1;
+
+    req.onreadystatechange = processStateChange;
+    req.open("get", "methods.cgi", true);
+    req.send("");
+
+    function processStateChange() {
+    
+      if (req.readyState == 4){
+        if (req.status == 200){
+          if (asyncStep == 1) {
+            asyncStep = 2;
+            log('get(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
+            req = new XMLHttpRequest();
+            req.onreadystatechange = processStateChange;
+            req.open("post", "methods.cgi", true);
+            req.send("");
+          } else if (asyncStep == 2) {
+            asyncStep = 3;
+            log('post(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
+            req = new XMLHttpRequest();
+            req.onreadystatechange = processStateChange;
+            req.open("DoIt", "methods.cgi", true);
+            req.send("");
+          } else if (asyncStep == 3) {
+            log('DoIt(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
+            if (window.layoutTestController)
+              layoutTestController.notifyDone();
+          }
+        }
+      }
+    }
+
+</script>
+</body>
+</html>
index 794e25ed4d07e9a5bb328a4e943b48c1b4b25545..45830abfced7dd147192ae23d007c1f3c6f5b8e2 100644 (file)
@@ -1,3 +1,16 @@
+2006-04-03  Alexey Proskuryakov  <ap@nypop.com>
+
+        Reviewed by Darin.
+
+        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=8099
+          REGRESSION: XMLHttpRequest lowercase post requests broken
+
+        Test: http/tests/xmlhttprequest/methods-lower-case.html
+
+        * xml/xmlhttprequest.cpp:
+        (WebCore::XMLHttpRequest::open): Uppercase some HTTP method names, to match a Firefox quirk.
+        (WebCore::XMLHttpRequest::send): Account for the above change.
+
 2006-04-02  Graham Dennis  <Graham.Dennis@gmail.com>
 
         Reviewed by Darin.
index c72225ab69cffb2c56b4d53c35b0f585eb46b9c1..7bc418a87e142e295d8102114fbf5115521b7c40 100644 (file)
@@ -271,7 +271,16 @@ void XMLHttpRequest::open(const String& method, const KURL& url, bool async, con
     if (!password.isNull())
         m_url.setPass(password.deprecatedString());
 
-    m_method = method.deprecatedString();
+    // Methods names are case-sensitive, but Firefox uppercases methods it knows
+    String methodUpper(method.upper());
+    if (methodUpper == "CONNECT" || methodUpper == "COPY" || methodUpper == "DELETE" || methodUpper == "GET" || methodUpper == "HEAD"
+        || methodUpper == "INDEX" || methodUpper == "LOCK" || methodUpper == "M-POST" || methodUpper == "MKCOL" || methodUpper == "MOVE" 
+        || methodUpper == "OPTIONS" || methodUpper == "POST" || methodUpper == "PROPFIND" || methodUpper == "PROPPATCH" || methodUpper == "PUT" 
+        || methodUpper == "TRACE" || methodUpper == "UNLOCK")
+        m_method = methodUpper.deprecatedString();
+    else
+        m_method = method.deprecatedString();
+
     m_async = async;
 
     changeState(Loading);
@@ -291,7 +300,7 @@ void XMLHttpRequest::send(const String& body)
 
     m_aborted = false;
 
-    if (!body.isNull() && m_method.lower() != "get" && m_method.lower() != "head" && (m_url.protocol().lower() == "http" || m_url.protocol().lower() == "https")) {
+    if (!body.isNull() && m_method != "GET" && m_method != "HEAD" && (m_url.protocol().lower() == "http" || m_url.protocol().lower() == "https")) {
         String contentType = getRequestHeader("Content-Type");
         String charset;
         if (contentType.isEmpty())
@@ -309,7 +318,7 @@ void XMLHttpRequest::send(const String& body)
         m_job = new TransferJob(m_async ? this : 0, m_method, m_url, m_encoding.fromUnicode(body.deprecatedString()));
     } else {
         // FIXME: HEAD requests just crash; see <rdar://4460899> and the commented out tests in http/tests/xmlhttprequest/methods.html.
-        if (m_method.lower() == "head")
+        if (m_method == "HEAD")
             m_method = "GET";
         m_job = new TransferJob(m_async ? this : 0, m_method, m_url);
     }