Title: [173060] trunk
Revision
173060
Author
carlo...@webkit.org
Date
2014-08-28 06:11:21 -0700 (Thu, 28 Aug 2014)

Log Message

[GTK] Add webkit_uri_response_get_http_headers to WebKit2 GTK+ API
https://bugs.webkit.org/show_bug.cgi?id=136248

Reviewed by Gustavo Noronha Silva.

Source/WebCore:

Move the code to update the SoupMessageHeaders to a new public
method.

* platform/network/soup/ResourceResponse.h:
* platform/network/soup/ResourceResponseSoup.cpp:
(WebCore::ResourceResponse::updateSoupMessageHeaders):
(WebCore::ResourceResponse::toSoupMessage):

Source/WebKit2:

Add webkit_uri_response_get_http_headers() that returns the HTTP
headers as a SoupMessageHeaders* like webkit_uri_request_get_http_headers().

* UIProcess/API/gtk/WebKitURIResponse.cpp:
(webkitURIResponseGetProperty): Add http-headers property getter.
(webkit_uri_response_class_init): Add http-headers property.
(webkit_uri_response_get_http_headers): Return the HTTP headers as
a SoupMessageHeaders* or NULL for non HTTP responses.
* UIProcess/API/gtk/WebKitURIResponse.h:
* UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbol.

Tools:

Add new test case for webkit_uri_response_get_http_headers().

* TestWebKitAPI/Tests/WebKit2Gtk/TestLoaderClient.cpp:
(testURIResponseHTTPHeaders):
(serverCallback):
(beforeAll):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (173059 => 173060)


--- trunk/Source/WebCore/ChangeLog	2014-08-28 09:13:58 UTC (rev 173059)
+++ trunk/Source/WebCore/ChangeLog	2014-08-28 13:11:21 UTC (rev 173060)
@@ -1,5 +1,20 @@
 2014-08-28  Carlos Garcia Campos  <cgar...@igalia.com>
 
+        [GTK] Add webkit_uri_response_get_http_headers to WebKit2 GTK+ API
+        https://bugs.webkit.org/show_bug.cgi?id=136248
+
+        Reviewed by Gustavo Noronha Silva.
+
+        Move the code to update the SoupMessageHeaders to a new public
+        method.
+
+        * platform/network/soup/ResourceResponse.h:
+        * platform/network/soup/ResourceResponseSoup.cpp:
+        (WebCore::ResourceResponse::updateSoupMessageHeaders):
+        (WebCore::ResourceResponse::toSoupMessage):
+
+2014-08-28  Carlos Garcia Campos  <cgar...@igalia.com>
+
         [GTK] Remove support for GTK+2 theme rendering
         https://bugs.webkit.org/show_bug.cgi?id=136285
 

Modified: trunk/Source/WebCore/platform/network/soup/ResourceResponse.h (173059 => 173060)


--- trunk/Source/WebCore/platform/network/soup/ResourceResponse.h	2014-08-28 09:13:58 UTC (rev 173059)
+++ trunk/Source/WebCore/platform/network/soup/ResourceResponse.h	2014-08-28 13:11:21 UTC (rev 173060)
@@ -58,6 +58,7 @@
     }
 
     SoupMessage* toSoupMessage() const;
+    void updateSoupMessageHeaders(SoupMessageHeaders*) const;
     void updateFromSoupMessage(SoupMessage*);
     void updateFromSoupMessageHeaders(const SoupMessageHeaders*);
 

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


--- trunk/Source/WebCore/platform/network/soup/ResourceResponseSoup.cpp	2014-08-28 09:13:58 UTC (rev 173059)
+++ trunk/Source/WebCore/platform/network/soup/ResourceResponseSoup.cpp	2014-08-28 13:11:21 UTC (rev 173060)
@@ -33,6 +33,12 @@
 
 namespace WebCore {
 
+void ResourceResponse::updateSoupMessageHeaders(SoupMessageHeaders* soupHeaders) const
+{
+    for (const auto& header : httpHeaderFields())
+        soup_message_headers_append(soupHeaders, header.key.utf8().data(), header.value.utf8().data());
+}
+
 SoupMessage* ResourceResponse::toSoupMessage() const
 {
     // This GET here is just because SoupMessage wants it, we dn't really know.
@@ -42,13 +48,7 @@
 
     soupMessage->status_code = httpStatusCode();
 
-    const HTTPHeaderMap& headers = httpHeaderFields();
-    SoupMessageHeaders* soupHeaders = soupMessage->response_headers;
-    if (!headers.isEmpty()) {
-        HTTPHeaderMap::const_iterator end = headers.end();
-        for (HTTPHeaderMap::const_iterator it = headers.begin(); it != end; ++it)
-            soup_message_headers_append(soupHeaders, it->key.utf8().data(), it->value.utf8().data());
-    }
+    updateSoupMessageHeaders(soupMessage->response_headers);
 
     soup_message_set_flags(soupMessage, m_soupFlags);
 

Modified: trunk/Source/WebKit2/ChangeLog (173059 => 173060)


--- trunk/Source/WebKit2/ChangeLog	2014-08-28 09:13:58 UTC (rev 173059)
+++ trunk/Source/WebKit2/ChangeLog	2014-08-28 13:11:21 UTC (rev 173060)
@@ -1,3 +1,21 @@
+2014-08-28  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Add webkit_uri_response_get_http_headers to WebKit2 GTK+ API
+        https://bugs.webkit.org/show_bug.cgi?id=136248
+
+        Reviewed by Gustavo Noronha Silva.
+
+        Add webkit_uri_response_get_http_headers() that returns the HTTP
+        headers as a SoupMessageHeaders* like webkit_uri_request_get_http_headers().
+
+        * UIProcess/API/gtk/WebKitURIResponse.cpp:
+        (webkitURIResponseGetProperty): Add http-headers property getter.
+        (webkit_uri_response_class_init): Add http-headers property.
+        (webkit_uri_response_get_http_headers): Return the HTTP headers as
+        a SoupMessageHeaders* or NULL for non HTTP responses.
+        * UIProcess/API/gtk/WebKitURIResponse.h:
+        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbol.
+
 2014-08-27  Zalan Bujtas  <za...@apple.com>
 
         Subpixel layout: Rename LayoutRect's device pixel snapping functions.

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp (173059 => 173060)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp	2014-08-28 09:13:58 UTC (rev 173059)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp	2014-08-28 13:11:21 UTC (rev 173060)
@@ -22,6 +22,7 @@
 
 #include "WebKitPrivate.h"
 #include "WebKitURIResponsePrivate.h"
+#include <WebCore/GUniquePtrSoup.h>
 #include <glib/gi18n-lib.h>
 #include <wtf/text/CString.h>
 
@@ -46,7 +47,8 @@
     PROP_STATUS_CODE,
     PROP_CONTENT_LENGTH,
     PROP_MIME_TYPE,
-    PROP_SUGGESTED_FILENAME
+    PROP_SUGGESTED_FILENAME,
+    PROP_HTTP_HEADERS
 };
 
 struct _WebKitURIResponsePrivate {
@@ -54,6 +56,7 @@
     CString uri;
     CString mimeType;
     CString suggestedFilename;
+    GUniquePtr<SoupMessageHeaders> httpHeaders;
 };
 
 WEBKIT_DEFINE_TYPE(WebKitURIResponse, webkit_uri_response, G_TYPE_OBJECT)
@@ -78,6 +81,9 @@
     case PROP_SUGGESTED_FILENAME:
         g_value_set_string(value, webkit_uri_response_get_suggested_filename(response));
         break;
+    case PROP_HTTP_HEADERS:
+        g_value_set_boxed(value, webkit_uri_response_get_http_headers(response));
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
     }
@@ -151,6 +157,23 @@
                                                         _("The suggested filename for the URI response"),
                                                         0,
                                                         WEBKIT_PARAM_READABLE));
+
+    /**
+     * WebKitURIResponse:http-headers:
+     *
+     * The HTTP headers of the response, or %NULL if the response is not an HTTP response.
+     *
+     * Since: 2.6
+     */
+    g_object_class_install_property(
+        objectClass,
+        PROP_HTTP_HEADERS,
+        g_param_spec_boxed(
+            "http-headers",
+            _("HTTP Headers"),
+            _("The The HTTP headers of the response"),
+            SOUP_TYPE_MESSAGE_HEADERS,
+            WEBKIT_PARAM_READABLE));
 }
 
 /**
@@ -237,6 +260,31 @@
     return response->priv->suggestedFilename.data();
 }
 
+/**
+ * webkit_uri_response_get_http_headers:
+ * @response: a #WebKitURIResponse
+ *
+ * Get the HTTP headers of a #WebKitURIResponse as a #SoupMessageHeaders.
+ *
+ * Returns: (transfer none): a #SoupMessageHeaders with the HTTP headers of @response
+ *    or %NULL if @response is not an HTTP response.
+ * Since: 2.6
+ */
+SoupMessageHeaders* webkit_uri_response_get_http_headers(WebKitURIResponse* response)
+{
+    g_return_val_if_fail(WEBKIT_IS_URI_RESPONSE(response), nullptr);
+
+    if (response->priv->httpHeaders)
+        return response->priv->httpHeaders.get();
+
+    if (!response->priv->resourceResponse.url().protocolIsInHTTPFamily())
+        return nullptr;
+
+    response->priv->httpHeaders.reset(soup_message_headers_new(SOUP_MESSAGE_HEADERS_RESPONSE));
+    response->priv->resourceResponse.updateSoupMessageHeaders(response->priv->httpHeaders.get());
+    return response->priv->httpHeaders.get();
+}
+
 WebKitURIResponse* webkitURIResponseCreateForResourceResponse(const WebCore::ResourceResponse& resourceResponse)
 {
     WebKitURIResponse* uriResponse = WEBKIT_URI_RESPONSE(g_object_new(WEBKIT_TYPE_URI_RESPONSE, NULL));

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h (173059 => 173060)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h	2014-08-28 09:13:58 UTC (rev 173059)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h	2014-08-28 13:11:21 UTC (rev 173060)
@@ -25,6 +25,7 @@
 #define WebKitURIResponse_h
 
 #include <gio/gio.h>
+#include <libsoup/soup.h>
 #include <webkit2/WebKitDefines.h>
 
 G_BEGIN_DECLS
@@ -74,6 +75,9 @@
 WEBKIT_API const gchar *
 webkit_uri_response_get_suggested_filename (WebKitURIResponse    *response);
 
+WEBKIT_API SoupMessageHeaders *
+webkit_uri_response_get_http_headers       (WebKitURIResponse    *response);
+
 G_END_DECLS
 
 #endif

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt (173059 => 173060)


--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2014-08-28 09:13:58 UTC (rev 173059)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2014-08-28 13:11:21 UTC (rev 173060)
@@ -468,6 +468,7 @@
 webkit_uri_response_get_content_length
 webkit_uri_response_get_mime_type
 webkit_uri_response_get_suggested_filename
+webkit_uri_response_get_http_headers
 
 <SUBSECTION Standard>
 WebKitURIResponseClass

Modified: trunk/Tools/ChangeLog (173059 => 173060)


--- trunk/Tools/ChangeLog	2014-08-28 09:13:58 UTC (rev 173059)
+++ trunk/Tools/ChangeLog	2014-08-28 13:11:21 UTC (rev 173060)
@@ -1,3 +1,17 @@
+2014-08-28  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Add webkit_uri_response_get_http_headers to WebKit2 GTK+ API
+        https://bugs.webkit.org/show_bug.cgi?id=136248
+
+        Reviewed by Gustavo Noronha Silva.
+
+        Add new test case for webkit_uri_response_get_http_headers().
+
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestLoaderClient.cpp:
+        (testURIResponseHTTPHeaders):
+        (serverCallback):
+        (beforeAll):
+
 2014-08-27  Alexey Proskuryakov  <a...@apple.com>
 
         EWS status link at build.webkit.org/dashboard is incorrect until EWS pop-up is opened

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestLoaderClient.cpp (173059 => 173060)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestLoaderClient.cpp	2014-08-28 09:13:58 UTC (rev 173059)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestLoaderClient.cpp	2014-08-28 13:11:21 UTC (rev 173060)
@@ -396,6 +396,27 @@
     g_assert(!strncmp(mainResourceData, "1", mainResourceDataSize));
 }
 
+static void testURIResponseHTTPHeaders(WebViewTest* test, gconstpointer)
+{
+    test->loadHtml("<html><body>No HTTP headers</body></html>", "file:///");
+    test->waitUntilLoadFinished();
+    WebKitWebResource* resource = webkit_web_view_get_main_resource(test->m_webView);
+    g_assert(WEBKIT_IS_WEB_RESOURCE(resource));
+    WebKitURIResponse* response = webkit_web_resource_get_response(resource);
+    g_assert(WEBKIT_IS_URI_RESPONSE(response));
+    g_assert(!webkit_uri_response_get_http_headers(response));
+
+    test->loadURI(kServer->getURIForPath("/headers").data());
+    test->waitUntilLoadFinished();
+    resource = webkit_web_view_get_main_resource(test->m_webView);
+    g_assert(WEBKIT_IS_WEB_RESOURCE(resource));
+    response = webkit_web_resource_get_response(resource);
+    g_assert(WEBKIT_IS_URI_RESPONSE(response));
+    SoupMessageHeaders* headers = webkit_uri_response_get_http_headers(response);
+    g_assert(headers);
+    g_assert_cmpstr(soup_message_headers_get_one(headers, "Foo"), ==, "bar");
+}
+
 static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
 {
     static const char* responseString = "<html><body>Testing!Testing!Testing!Testing!Testing!Testing!Testing!"
@@ -433,6 +454,9 @@
         else
             soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, kDNTHeaderNotPresent, strlen(kDNTHeaderNotPresent));
         soup_message_set_status(message, SOUP_STATUS_OK);
+    } else if (g_str_equal(path, "/headers")) {
+        soup_message_headers_append(message->response_headers, "Foo", "bar");
+        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, responseString, strlen(responseString));
     } else
         soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
 
@@ -469,6 +493,7 @@
     ViewIsLoadingTest::add("WebKitWebView", "is-loading", testWebViewIsLoading);
     WebPageURITest::add("WebKitWebPage", "get-uri", testWebPageURI);
     WebViewTest::add("WebKitURIRequest", "http-headers", testURIRequestHTTPHeaders);
+    WebViewTest::add("WebKitURIResponse", "http-headers", testURIResponseHTTPHeaders);
 }
 
 void afterAll()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to