Changeset 231350 in webkit


Ignore:
Timestamp:
May 4, 2018 3:14:27 AM (6 years ago)
Author:
Carlos Garcia Campos
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):

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r231346 r231350  
     12018-05-04  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Epiphany (GNOME Web) says "Error downloading: Service Unavailable." when trying to download an image from discogs.com
     4        https://bugs.webkit.org/show_bug.cgi?id=174730
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Export ResourceRequestBase::hasHTTPHeaderField().
     9
     10        * platform/network/ResourceRequestBase.h:
     11
    1122018-05-03  Yusuke Suzuki  <utatane.tea@gmail.com>
    213
  • trunk/Source/WebCore/platform/network/ResourceRequestBase.h

    r230944 r231350  
    104104    WEBCORE_EXPORT void addHTTPHeaderFieldIfNotPresent(HTTPHeaderName, const String&);
    105105
    106     bool hasHTTPHeaderField(HTTPHeaderName) const;
     106    WEBCORE_EXPORT bool hasHTTPHeaderField(HTTPHeaderName) const;
    107107
    108108    // Instead of passing a string literal to any of these functions, just use a HTTPHeaderName instead.
  • trunk/Source/WebKit/ChangeLog

    r231349 r231350  
     12018-05-04  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Epiphany (GNOME Web) says "Error downloading: Service Unavailable." when trying to download an image from discogs.com
     4        https://bugs.webkit.org/show_bug.cgi?id=174730
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        The problem is that we don't send any User-Agent HTTP header for downloads started by WebProcessPool::download().
     9
     10        * UIProcess/API/glib/WebKitDownload.cpp:
     11        (webkitDownloadUpdateRequest): Helper to update the cached request.
     12        (webkitDownloadStarted): Updated the cached request if we have one.
     13        (webkit_download_get_request): Use webkitDownloadUpdateRequest().
     14        * UIProcess/API/glib/WebKitDownloadClient.cpp:
     15        * UIProcess/API/glib/WebKitDownloadPrivate.h:
     16        * UIProcess/WebProcessPool.cpp:
     17        (WebKit::WebProcessPool::download): Set the User-Agent HTTP header if there isn't any.
     18
    1192018-05-04  Carlos Garcia Campos  <cgarcia@igalia.com>
    220
  • trunk/Source/WebKit/UIProcess/API/glib/WebKitDownload.cpp

    r218487 r231350  
    324324}
    325325
     326static void webkitDownloadUpdateRequest(WebKitDownload* download)
     327{
     328    download->priv->request = adoptGRef(webkitURIRequestCreateForResourceRequest(download->priv->download->request()));
     329}
     330
     331void webkitDownloadStarted(WebKitDownload* download)
     332{
     333    // Update with the final request if needed.
     334    if (download->priv->request)
     335        webkitDownloadUpdateRequest(download);
     336}
     337
    326338void webkitDownloadSetResponse(WebKitDownload* download, WebKitURIResponse* response)
    327339{
     
    437449WebKitURIRequest* webkit_download_get_request(WebKitDownload* download)
    438450{
    439     g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), 0);
     451    g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), nullptr);
    440452
    441453    WebKitDownloadPrivate* priv = download->priv;
    442454    if (!priv->request)
    443         priv->request = adoptGRef(webkitURIRequestCreateForResourceRequest(priv->download->request()));
     455        webkitDownloadUpdateRequest(download);
    444456    return priv->request.get();
    445457}
  • trunk/Source/WebKit/UIProcess/API/glib/WebKitDownloadClient.cpp

    r223730 r231350  
    4444    {
    4545        GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(&downloadProxy);
     46        webkitDownloadStarted(download.get());
    4647        webkitWebContextDownloadStarted(m_webContext, download.get());
    4748    }
  • trunk/Source/WebKit/UIProcess/API/glib/WebKitDownloadPrivate.h

    r218487 r231350  
    2525
    2626WebKitDownload* webkitDownloadCreate(WebKit::DownloadProxy*);
     27void webkitDownloadStarted(WebKitDownload*);
    2728bool webkitDownloadIsCancelled(WebKitDownload*);
    2829void webkitDownloadSetResponse(WebKitDownload*, WebKitURIResponse*);
  • trunk/Source/WebKit/UIProcess/WebProcessPool.cpp

    r231306 r231350  
    12161216            updatedRequest.setFirstPartyForCookies(initiatingPageURL);
    12171217            updatedRequest.setIsSameSite(registrableDomainsAreEqual(initiatingPageURL, request.url()));
     1218            if (!updatedRequest.hasHTTPHeaderField(HTTPHeaderName::UserAgent))
     1219                updatedRequest.setHTTPUserAgent(initiatingPage->userAgent());
    12181220        } else {
    12191221            updatedRequest.setFirstPartyForCookies(URL());
    12201222            updatedRequest.setIsSameSite(false);
     1223            if (!updatedRequest.hasHTTPHeaderField(HTTPHeaderName::UserAgent))
     1224                updatedRequest.setHTTPUserAgent(WebPageProxy::standardUserAgent());
    12211225        }
    12221226        updatedRequest.setIsTopSite(false);
  • trunk/Tools/ChangeLog

    r231336 r231350  
     12018-05-04  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Epiphany (GNOME Web) says "Error downloading: Service Unavailable." when trying to download an image from discogs.com
     4        https://bugs.webkit.org/show_bug.cgi?id=174730
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Update unit tests to check that User-Agent header is included in HTTP download requests.
     9
     10        * TestWebKitAPI/Tests/WebKitGLib/TestDownloads.cpp:
     11        (testDownloadRemoteFile):
     12        (testWebViewDownloadURI):
     13        (testPolicyResponseDownload):
     14        (testPolicyResponseDownloadCancel):
     15        (testDownloadMIMEType):
     16        (testContextMenuDownloadActions):
     17
    1182018-05-03  Ross Kirsling  <ross.kirsling@sony.com>
    219
  • trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestDownloads.cpp

    r224192 r231350  
    454454    ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, kServer->getURIForPath("/test.pdf"));
    455455
     456    auto headers = webkit_uri_request_get_http_headers(request);
     457    g_assert_nonnull(soup_message_headers_get_one(headers, "User-Agent"));
     458
    456459    g_assert(webkit_download_get_destination(download.get()));
    457460    g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), ==, 1);
     
    567570    test->waitUntilDownloadStarted();
    568571    g_assert(test->m_webView == webkit_download_get_web_view(download.get()));
     572
     573    WebKitURIRequest* request = webkit_download_get_request(download.get());
     574    g_assert(request);
     575    ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, kServer->getURIForPath("/test.pdf"));
     576
     577    auto headers = webkit_uri_request_get_http_headers(request);
     578    g_assert_nonnull(soup_message_headers_get_one(headers, "User-Agent"));
    569579    test->waitUntilDownloadFinished();
    570580
     
    620630
    621631    g_assert(test->m_webView == webkit_download_get_web_view(test->m_download.get()));
     632
     633    auto headers = webkit_uri_request_get_http_headers(request);
     634    g_assert_nonnull(soup_message_headers_get_one(headers, "User-Agent"));
    622635    test->waitUntilDownloadFinished();
    623636
     
    639652
    640653    g_assert(test->m_webView == webkit_download_get_web_view(test->m_download.get()));
     654
     655    auto headers = webkit_uri_request_get_http_headers(request);
     656    g_assert_nonnull(soup_message_headers_get_one(headers, "User-Agent"));
    641657    test->cancelDownloadAndWaitUntilFinished();
    642658}
     
    659675    WEBKIT_IS_URI_REQUEST(request);
    660676    ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, kServer->getURIForPath("/unknown"));
     677
     678    auto headers = webkit_uri_request_get_http_headers(request);
     679    g_assert_nonnull(soup_message_headers_get_one(headers, "User-Agent"));
    661680
    662681    WebKitURIResponse* response = webkit_download_get_response(download.get());
     
    719738
    720739    g_assert(test->m_webView == webkit_download_get_web_view(test->m_download.get()));
     740
     741    WebKitURIRequest* request = webkit_download_get_request(test->m_download.get());
     742    WEBKIT_IS_URI_REQUEST(request);
     743    ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, kServer->getURIForPath("/test.pdf"));
     744
     745    auto headers = webkit_uri_request_get_http_headers(request);
     746    g_assert_nonnull(soup_message_headers_get_one(headers, "User-Agent"));
     747
    721748    test->waitUntilDownloadFinished();
    722749
Note: See TracChangeset for help on using the changeset viewer.