[GTK] Add webkit_uri_response_get_http_headers to WebKit2 GTK+ API
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Aug 2014 13:11:21 +0000 (13:11 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Aug 2014 13:11:21 +0000 (13:11 +0000)
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):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/network/soup/ResourceResponse.h
Source/WebCore/platform/network/soup/ResourceResponseSoup.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp
Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h
Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestLoaderClient.cpp

index 89f36d6..e00c62e 100644 (file)
@@ -1,5 +1,20 @@
 2014-08-28  Carlos Garcia Campos  <cgarcia@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  <cgarcia@igalia.com>
+
         [GTK] Remove support for GTK+2 theme rendering
         https://bugs.webkit.org/show_bug.cgi?id=136285
 
index 13da2b1..a49808c 100644 (file)
@@ -58,6 +58,7 @@ public:
     }
 
     SoupMessage* toSoupMessage() const;
+    void updateSoupMessageHeaders(SoupMessageHeaders*) const;
     void updateFromSoupMessage(SoupMessage*);
     void updateFromSoupMessageHeaders(const SoupMessageHeaders*);
 
index cf8e33f..4947742 100644 (file)
 
 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* ResourceResponse::toSoupMessage() const
 
     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);
 
index 5c5648d..214acf7 100644 (file)
@@ -1,3 +1,21 @@
+2014-08-28  Carlos Garcia Campos  <cgarcia@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  <zalan@apple.com>
 
         Subpixel layout: Rename LayoutRect's device pixel snapping functions.
index 20ab248..b85fc43 100644 (file)
@@ -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 @@ enum {
     PROP_STATUS_CODE,
     PROP_CONTENT_LENGTH,
     PROP_MIME_TYPE,
-    PROP_SUGGESTED_FILENAME
+    PROP_SUGGESTED_FILENAME,
+    PROP_HTTP_HEADERS
 };
 
 struct _WebKitURIResponsePrivate {
@@ -54,6 +56,7 @@ struct _WebKitURIResponsePrivate {
     CString uri;
     CString mimeType;
     CString suggestedFilename;
+    GUniquePtr<SoupMessageHeaders> httpHeaders;
 };
 
 WEBKIT_DEFINE_TYPE(WebKitURIResponse, webkit_uri_response, G_TYPE_OBJECT)
@@ -78,6 +81,9 @@ static void webkitURIResponseGetProperty(GObject* object, guint propId, GValue*
     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 @@ static void webkit_uri_response_class_init(WebKitURIResponseClass* responseClass
                                                         _("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 @@ const gchar* webkit_uri_response_get_suggested_filename(WebKitURIResponse* respo
     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));
index d43eca1..6731616 100644 (file)
@@ -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_uri_response_get_mime_type          (WebKitURIResponse    *response);
 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
index 7c48033..85ecf71 100644 (file)
@@ -468,6 +468,7 @@ webkit_uri_response_get_status_code
 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
index 9d06cf5..28d7121 100644 (file)
@@ -1,3 +1,17 @@
+2014-08-28  Carlos Garcia Campos  <cgarcia@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  <ap@apple.com>
 
         EWS status link at build.webkit.org/dashboard is incorrect until EWS pop-up is opened
index 5a0d608..88353c0 100644 (file)
@@ -396,6 +396,27 @@ static void testURIRequestHTTPHeaders(WebViewTest* test, gconstpointer)
     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 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char*
         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 @@ void beforeAll()
     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()