Title: [136705] trunk
Revision
136705
Author
[email protected]
Date
2012-12-05 09:44:40 -0800 (Wed, 05 Dec 2012)

Log Message

[EFL][GTK] List value response headers are not handled in RespourceResponse (libsoup specific)
https://bugs.webkit.org/show_bug.cgi?id=95181

Patch by Alexander Shalamov <[email protected]> on 2012-12-05
Reviewed by Martin Robinson.

Source/WebCore:

When list-value response headers are received, they are handled as single
value headers. This patch fixes incorrect behavior. New test was added to
verify list-value header handling.

Test: http/tests/xmlhttprequest/xmlhttprequest-test-custom-headers.html

* platform/network/soup/ResourceResponseSoup.cpp:
(WebCore::ResourceResponse::updateFromSoupMessage):

LayoutTests:

Added test that checks if list-value response headers handled correctly.

* http/tests/xmlhttprequest/resources/custom-headers.php: Added.
* http/tests/xmlhttprequest/xmlhttprequest-test-custom-headers-expected.txt: Added.
* http/tests/xmlhttprequest/xmlhttprequest-test-custom-headers.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (136704 => 136705)


--- trunk/LayoutTests/ChangeLog	2012-12-05 17:42:27 UTC (rev 136704)
+++ trunk/LayoutTests/ChangeLog	2012-12-05 17:44:40 UTC (rev 136705)
@@ -1,3 +1,16 @@
+2012-12-05  Alexander Shalamov  <[email protected]>
+
+        [EFL][GTK] List value response headers are not handled in RespourceResponse (libsoup specific)
+        https://bugs.webkit.org/show_bug.cgi?id=95181
+
+        Reviewed by Martin Robinson.
+
+        Added test that checks if list-value response headers handled correctly.
+
+        * http/tests/xmlhttprequest/resources/custom-headers.php: Added.
+        * http/tests/xmlhttprequest/xmlhttprequest-test-custom-headers-expected.txt: Added.
+        * http/tests/xmlhttprequest/xmlhttprequest-test-custom-headers.html: Added.
+
 2012-12-05  Krzysztof Czech  <[email protected]>
 
         [EFL][WK2] Introduce WebKit-EFL to Assistive Technologies - new baselines

Added: trunk/LayoutTests/http/tests/xmlhttprequest/resources/custom-headers.php (0 => 136705)


--- trunk/LayoutTests/http/tests/xmlhttprequest/resources/custom-headers.php	                        (rev 0)
+++ trunk/LayoutTests/http/tests/xmlhttprequest/resources/custom-headers.php	2012-12-05 17:44:40 UTC (rev 136705)
@@ -0,0 +1,7 @@
+<?php
+ header("Content-Type: text/plain");
+ header("X-Custom-Header-Single: single");
+ header("X-Custom-Header-Empty:");
+ header("X-Custom-Header-List: one");
+ header("X-Custom-Header-List: two", false);
+?>
\ No newline at end of file

Added: trunk/LayoutTests/http/tests/xmlhttprequest/xmlhttprequest-test-custom-headers-expected.txt (0 => 136705)


--- trunk/LayoutTests/http/tests/xmlhttprequest/xmlhttprequest-test-custom-headers-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/xmlhttprequest/xmlhttprequest-test-custom-headers-expected.txt	2012-12-05 17:44:40 UTC (rev 136705)
@@ -0,0 +1,13 @@
+This test verifies that XMLHttpRequest properly handles list-valued headers.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS xhr.getResponseHeader("CONTENT-TYPE").indexOf("text/plain") is >= 0
+PASS xhr.getResponseHeader("x-custom-header-single") is "single"
+PASS xhr.getResponseHeader("x-custom-header-empty") is ""
+PASS xhr.getResponseHeader("x-custom-header-list") is "one, two"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/http/tests/xmlhttprequest/xmlhttprequest-test-custom-headers.html (0 => 136705)


--- trunk/LayoutTests/http/tests/xmlhttprequest/xmlhttprequest-test-custom-headers.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/xmlhttprequest/xmlhttprequest-test-custom-headers.html	2012-12-05 17:44:40 UTC (rev 136705)
@@ -0,0 +1,39 @@
+<html>
+<head>
+    <script src=""
+    <script type="text/_javascript_">
+    description('This test verifies that XMLHttpRequest properly handles list-valued headers.');
+    window.jsTestIsAsync = true;
+
+    var xhr;
+
+    if (window.XMLHttpRequest) {
+        xhr = new XMLHttpRequest();
+    } else {
+        try {
+            xhr = new ActiveXObject("Msxml2.XMLHTTP");
+        } catch (ex) {
+            xhr = new ActiveXObject("Microsoft.XMLHTTP");
+        }
+    }
+
+    xhr.open("GET", "resources/custom-headers.php");
+    xhr.send(null);
+
+    xhr._onreadystatechange_ = function() {
+        if(xhr.readyState == 4) {
+            shouldBeGreaterThanOrEqual("xhr.getResponseHeader(\"CONTENT-TYPE\").indexOf(\"text/plain\")", "0");
+            shouldBeEqualToString("xhr.getResponseHeader(\"x-custom-header-single\")", "single");
+            shouldBeEmptyString("xhr.getResponseHeader(\"x-custom-header-empty\")");
+            shouldBeEqualToString("xhr.getResponseHeader(\"x-custom-header-list\")", "one, two");
+            finishJSTest();
+        }
+    }
+
+    </script>
+    <script src=""
+</head>
+
+<body>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (136704 => 136705)


--- trunk/Source/WebCore/ChangeLog	2012-12-05 17:42:27 UTC (rev 136704)
+++ trunk/Source/WebCore/ChangeLog	2012-12-05 17:44:40 UTC (rev 136705)
@@ -1,3 +1,19 @@
+2012-12-05  Alexander Shalamov  <[email protected]>
+
+        [EFL][GTK] List value response headers are not handled in RespourceResponse (libsoup specific)
+        https://bugs.webkit.org/show_bug.cgi?id=95181
+
+        Reviewed by Martin Robinson.
+
+        When list-value response headers are received, they are handled as single
+        value headers. This patch fixes incorrect behavior. New test was added to
+        verify list-value header handling.
+
+        Test: http/tests/xmlhttprequest/xmlhttprequest-test-custom-headers.html
+
+        * platform/network/soup/ResourceResponseSoup.cpp:
+        (WebCore::ResourceResponse::updateFromSoupMessage):
+
 2012-12-05  Pavel Feldman  <[email protected]>
 
         Web Inspector: Don't include error message text in the editor buffer.

Modified: trunk/Source/WebCore/platform/network/soup/ResourceResponseSoup.cpp (136704 => 136705)


--- trunk/Source/WebCore/platform/network/soup/ResourceResponseSoup.cpp	2012-12-05 17:42:27 UTC (rev 136704)
+++ trunk/Source/WebCore/platform/network/soup/ResourceResponseSoup.cpp	2012-12-05 17:44:40 UTC (rev 136705)
@@ -26,6 +26,7 @@
 #include "MIMETypeRegistry.h"
 #include "SoupURIUtils.h"
 #include <wtf/text/CString.h>
+#include <wtf/text/StringBuilder.h>
 #include <wtf/text/WTFString.h>
 
 using namespace std;
@@ -67,10 +68,24 @@
     const char* headerName;
     const char* headerValue;
 
+    // updateFromSoupMessage could be called several times for the same ResourceResponse object,
+    // thus, we need to clear old header values and update m_httpHeaderFields from soupMessage headers.
+    m_httpHeaderFields.clear();
+
     soup_message_headers_iter_init(&headersIter, soupMessage->response_headers);
-    while (soup_message_headers_iter_next(&headersIter, &headerName, &headerValue))
-        m_httpHeaderFields.set(String::fromUTF8WithLatin1Fallback(headerName, strlen(headerName)),
-                               String::fromUTF8WithLatin1Fallback(headerValue, strlen(headerValue)));
+    while (soup_message_headers_iter_next(&headersIter, &headerName, &headerValue)) {
+        String headerNameString = String::fromUTF8WithLatin1Fallback(headerName, strlen(headerName));
+        HTTPHeaderMap::const_iterator it = m_httpHeaderFields.find(headerNameString);
+        if (it == m_httpHeaderFields.end() || (it != m_httpHeaderFields.end() && it->value.isEmpty()))
+            m_httpHeaderFields.set(headerNameString, String::fromUTF8WithLatin1Fallback(headerValue, strlen(headerValue)));
+        else {
+            StringBuilder builder;
+            builder.append(it->value);
+            builder.appendLiteral(", ");
+            builder.append(String::fromUTF8WithLatin1Fallback(headerValue, strlen(headerValue)));
+            m_httpHeaderFields.set(headerNameString, builder.toString());
+        }
+    }
 
     m_soupFlags = soup_message_get_flags(soupMessage);
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to