Title: [231350] trunk
Revision
231350
Author
[email protected]
Date
2018-05-04 03:14:27 -0700 (Fri, 04 May 2018)

Log Message

[GTK] Epiphany (GNOME Web) says "Error downloading: Service Unavailable." when trying to download an image from discogs.com
https://bugs.webkit.org/show_bug.cgi?id=174730

Reviewed by Michael Catanzaro.

Source/WebCore:

Export ResourceRequestBase::hasHTTPHeaderField().

* platform/network/ResourceRequestBase.h:

Source/WebKit:

The problem is that we don't send any User-Agent HTTP header for downloads started by WebProcessPool::download().

* UIProcess/API/glib/WebKitDownload.cpp:
(webkitDownloadUpdateRequest): Helper to update the cached request.
(webkitDownloadStarted): Updated the cached request if we have one.
(webkit_download_get_request): Use webkitDownloadUpdateRequest().
* UIProcess/API/glib/WebKitDownloadClient.cpp:
* UIProcess/API/glib/WebKitDownloadPrivate.h:
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::download): Set the User-Agent HTTP header if there isn't any.

Tools:

Update unit tests to check that User-Agent header is included in HTTP download requests.

* TestWebKitAPI/Tests/WebKitGLib/TestDownloads.cpp:
(testDownloadRemoteFile):
(testWebViewDownloadURI):
(testPolicyResponseDownload):
(testPolicyResponseDownloadCancel):
(testDownloadMIMEType):
(testContextMenuDownloadActions):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (231349 => 231350)


--- trunk/Source/WebCore/ChangeLog	2018-05-04 10:12:03 UTC (rev 231349)
+++ trunk/Source/WebCore/ChangeLog	2018-05-04 10:14:27 UTC (rev 231350)
@@ -1,3 +1,14 @@
+2018-05-04  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Epiphany (GNOME Web) says "Error downloading: Service Unavailable." when trying to download an image from discogs.com
+        https://bugs.webkit.org/show_bug.cgi?id=174730
+
+        Reviewed by Michael Catanzaro.
+
+        Export ResourceRequestBase::hasHTTPHeaderField().
+
+        * platform/network/ResourceRequestBase.h:
+
 2018-05-03  Yusuke Suzuki  <[email protected]>
 
         Use subprocess.call instead of os.system to handle path with spaces

Modified: trunk/Source/WebCore/platform/network/ResourceRequestBase.h (231349 => 231350)


--- trunk/Source/WebCore/platform/network/ResourceRequestBase.h	2018-05-04 10:12:03 UTC (rev 231349)
+++ trunk/Source/WebCore/platform/network/ResourceRequestBase.h	2018-05-04 10:14:27 UTC (rev 231350)
@@ -103,7 +103,7 @@
     WEBCORE_EXPORT void addHTTPHeaderField(const String& name, const String& value);
     WEBCORE_EXPORT void addHTTPHeaderFieldIfNotPresent(HTTPHeaderName, const String&);
 
-    bool hasHTTPHeaderField(HTTPHeaderName) const;
+    WEBCORE_EXPORT bool hasHTTPHeaderField(HTTPHeaderName) const;
 
     // Instead of passing a string literal to any of these functions, just use a HTTPHeaderName instead.
     template<size_t length> String httpHeaderField(const char (&)[length]) const = delete;

Modified: trunk/Source/WebKit/ChangeLog (231349 => 231350)


--- trunk/Source/WebKit/ChangeLog	2018-05-04 10:12:03 UTC (rev 231349)
+++ trunk/Source/WebKit/ChangeLog	2018-05-04 10:14:27 UTC (rev 231350)
@@ -1,5 +1,23 @@
 2018-05-04  Carlos Garcia Campos  <[email protected]>
 
+        [GTK] Epiphany (GNOME Web) says "Error downloading: Service Unavailable." when trying to download an image from discogs.com
+        https://bugs.webkit.org/show_bug.cgi?id=174730
+
+        Reviewed by Michael Catanzaro.
+
+        The problem is that we don't send any User-Agent HTTP header for downloads started by WebProcessPool::download().
+
+        * UIProcess/API/glib/WebKitDownload.cpp:
+        (webkitDownloadUpdateRequest): Helper to update the cached request.
+        (webkitDownloadStarted): Updated the cached request if we have one.
+        (webkit_download_get_request): Use webkitDownloadUpdateRequest().
+        * UIProcess/API/glib/WebKitDownloadClient.cpp:
+        * UIProcess/API/glib/WebKitDownloadPrivate.h:
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::download): Set the User-Agent HTTP header if there isn't any.
+
+2018-05-04  Carlos Garcia Campos  <[email protected]>
+
         [GTK] Some event tests failing after r230817
         https://bugs.webkit.org/show_bug.cgi?id=185072
 

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitDownload.cpp (231349 => 231350)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitDownload.cpp	2018-05-04 10:12:03 UTC (rev 231349)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitDownload.cpp	2018-05-04 10:14:27 UTC (rev 231350)
@@ -323,6 +323,18 @@
     return download;
 }
 
+static void webkitDownloadUpdateRequest(WebKitDownload* download)
+{
+    download->priv->request = adoptGRef(webkitURIRequestCreateForResourceRequest(download->priv->download->request()));
+}
+
+void webkitDownloadStarted(WebKitDownload* download)
+{
+    // Update with the final request if needed.
+    if (download->priv->request)
+        webkitDownloadUpdateRequest(download);
+}
+
 void webkitDownloadSetResponse(WebKitDownload* download, WebKitURIResponse* response)
 {
     download->priv->response = response;
@@ -436,11 +448,11 @@
  */
 WebKitURIRequest* webkit_download_get_request(WebKitDownload* download)
 {
-    g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), 0);
+    g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), nullptr);
 
     WebKitDownloadPrivate* priv = download->priv;
     if (!priv->request)
-        priv->request = adoptGRef(webkitURIRequestCreateForResourceRequest(priv->download->request()));
+        webkitDownloadUpdateRequest(download);
     return priv->request.get();
 }
 

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitDownloadClient.cpp (231349 => 231350)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitDownloadClient.cpp	2018-05-04 10:12:03 UTC (rev 231349)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitDownloadClient.cpp	2018-05-04 10:14:27 UTC (rev 231350)
@@ -43,6 +43,7 @@
     void didStart(WebProcessPool&, DownloadProxy& downloadProxy) override
     {
         GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(&downloadProxy);
+        webkitDownloadStarted(download.get());
         webkitWebContextDownloadStarted(m_webContext, download.get());
     }
 

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitDownloadPrivate.h (231349 => 231350)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitDownloadPrivate.h	2018-05-04 10:12:03 UTC (rev 231349)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitDownloadPrivate.h	2018-05-04 10:14:27 UTC (rev 231350)
@@ -24,6 +24,7 @@
 #include <WebCore/ResourceRequest.h>
 
 WebKitDownload* webkitDownloadCreate(WebKit::DownloadProxy*);
+void webkitDownloadStarted(WebKitDownload*);
 bool webkitDownloadIsCancelled(WebKitDownload*);
 void webkitDownloadSetResponse(WebKitDownload*, WebKitURIResponse*);
 void webkitDownloadSetWebView(WebKitDownload*, WebKitWebView*);

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (231349 => 231350)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2018-05-04 10:12:03 UTC (rev 231349)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2018-05-04 10:14:27 UTC (rev 231350)
@@ -1215,9 +1215,13 @@
             URL initiatingPageURL = URL { URL { }, initiatingPage->pageLoadState().url() };
             updatedRequest.setFirstPartyForCookies(initiatingPageURL);
             updatedRequest.setIsSameSite(registrableDomainsAreEqual(initiatingPageURL, request.url()));
+            if (!updatedRequest.hasHTTPHeaderField(HTTPHeaderName::UserAgent))
+                updatedRequest.setHTTPUserAgent(initiatingPage->userAgent());
         } else {
             updatedRequest.setFirstPartyForCookies(URL());
             updatedRequest.setIsSameSite(false);
+            if (!updatedRequest.hasHTTPHeaderField(HTTPHeaderName::UserAgent))
+                updatedRequest.setHTTPUserAgent(WebPageProxy::standardUserAgent());
         }
         updatedRequest.setIsTopSite(false);
         networkProcess()->send(Messages::NetworkProcess::DownloadRequest(sessionID, downloadProxy->downloadID(), updatedRequest, suggestedFilename), 0);

Modified: trunk/Tools/ChangeLog (231349 => 231350)


--- trunk/Tools/ChangeLog	2018-05-04 10:12:03 UTC (rev 231349)
+++ trunk/Tools/ChangeLog	2018-05-04 10:14:27 UTC (rev 231350)
@@ -1,3 +1,20 @@
+2018-05-04  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Epiphany (GNOME Web) says "Error downloading: Service Unavailable." when trying to download an image from discogs.com
+        https://bugs.webkit.org/show_bug.cgi?id=174730
+
+        Reviewed by Michael Catanzaro.
+
+        Update unit tests to check that User-Agent header is included in HTTP download requests.
+
+        * TestWebKitAPI/Tests/WebKitGLib/TestDownloads.cpp:
+        (testDownloadRemoteFile):
+        (testWebViewDownloadURI):
+        (testPolicyResponseDownload):
+        (testPolicyResponseDownloadCancel):
+        (testDownloadMIMEType):
+        (testContextMenuDownloadActions):
+
 2018-05-03  Ross Kirsling  <[email protected]>
 
         [WinCairo] Test archive must use Python zipfile, just like build product.

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestDownloads.cpp (231349 => 231350)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestDownloads.cpp	2018-05-04 10:12:03 UTC (rev 231349)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestDownloads.cpp	2018-05-04 10:14:27 UTC (rev 231350)
@@ -453,6 +453,9 @@
     g_assert(request);
     ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, kServer->getURIForPath("/test.pdf"));
 
+    auto headers = webkit_uri_request_get_http_headers(request);
+    g_assert_nonnull(soup_message_headers_get_one(headers, "User-Agent"));
+
     g_assert(webkit_download_get_destination(download.get()));
     g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), ==, 1);
     GUniquePtr<char> expectedFilename(g_strdup_printf("%s.pdf", kServerSuggestedFilename));
@@ -566,6 +569,13 @@
     test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(download.get()));
     test->waitUntilDownloadStarted();
     g_assert(test->m_webView == webkit_download_get_web_view(download.get()));
+
+    WebKitURIRequest* request = webkit_download_get_request(download.get());
+    g_assert(request);
+    ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, kServer->getURIForPath("/test.pdf"));
+
+    auto headers = webkit_uri_request_get_http_headers(request);
+    g_assert_nonnull(soup_message_headers_get_one(headers, "User-Agent"));
     test->waitUntilDownloadFinished();
 
     GRefPtr<GFile> downloadFile = adoptGRef(g_file_new_for_uri(webkit_download_get_destination(download.get())));
@@ -619,6 +629,9 @@
     ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, requestURI);
 
     g_assert(test->m_webView == webkit_download_get_web_view(test->m_download.get()));
+
+    auto headers = webkit_uri_request_get_http_headers(request);
+    g_assert_nonnull(soup_message_headers_get_one(headers, "User-Agent"));
     test->waitUntilDownloadFinished();
 
     GRefPtr<GFile> downloadFile = adoptGRef(g_file_new_for_uri(webkit_download_get_destination(test->m_download.get())));
@@ -638,6 +651,9 @@
     ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, requestURI);
 
     g_assert(test->m_webView == webkit_download_get_web_view(test->m_download.get()));
+
+    auto headers = webkit_uri_request_get_http_headers(request);
+    g_assert_nonnull(soup_message_headers_get_one(headers, "User-Agent"));
     test->cancelDownloadAndWaitUntilFinished();
 }
 
@@ -659,6 +675,9 @@
     WEBKIT_IS_URI_REQUEST(request);
     ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, kServer->getURIForPath("/unknown"));
 
+    auto headers = webkit_uri_request_get_http_headers(request);
+    g_assert_nonnull(soup_message_headers_get_one(headers, "User-Agent"));
+
     WebKitURIResponse* response = webkit_download_get_response(download.get());
     WEBKIT_IS_URI_RESPONSE(response);
     g_assert_cmpstr(webkit_uri_response_get_mime_type(response), ==, "application/pdf");
@@ -718,6 +737,14 @@
     test->waitUntilDownloadStarted();
 
     g_assert(test->m_webView == webkit_download_get_web_view(test->m_download.get()));
+
+    WebKitURIRequest* request = webkit_download_get_request(test->m_download.get());
+    WEBKIT_IS_URI_REQUEST(request);
+    ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, kServer->getURIForPath("/test.pdf"));
+
+    auto headers = webkit_uri_request_get_http_headers(request);
+    g_assert_nonnull(soup_message_headers_get_one(headers, "User-Agent"));
+
     test->waitUntilDownloadFinished();
 
     GRefPtr<GFile> downloadFile = adoptGRef(g_file_new_for_uri(webkit_download_get_destination(test->m_download.get())));
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to