Title: [266576] trunk
Revision
266576
Author
carlo...@webkit.org
Date
2020-09-03 22:13:53 -0700 (Thu, 03 Sep 2020)

Log Message

[GTK] Unexpected User-Agent on redirect
https://bugs.webkit.org/show_bug.cgi?id=191858

Reviewed by Youenn Fablet.

Source/WebKit:

Clear the user agent on new request after a redirect to ensure a new one is computed taking into account the
quirks if needed. Also ensure quirks are applied for downloads started in the UI process.

* NetworkProcess/soup/NetworkDataTaskSoup.cpp:
(WebKit::NetworkDataTaskSoup::continueHTTPRedirection): Clear the user agent on new request.
* UIProcess/API/glib/WebKitDownloadClient.cpp:
* UIProcess/WebPageProxy.h: Add userAgentForURL().
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::download): Use userAgentForURL() instead of userAgent().
* UIProcess/gtk/WebPageProxyGtk.cpp:
(WebKit::WebPageProxy::userAgentForURL): Implement it to apply quirks if needed.
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::userAgentForURL): Just return the web page user agent.
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::userAgentForURL): Ditto.
* UIProcess/playstation/WebPageProxyPlayStation.cpp:
(WebKit::WebPageProxy::userAgentForURL): Ditto.
* UIProcess/win/WebPageProxyWin.cpp:
(WebKit::WebPageProxy::userAgentForURL): Ditto.
* UIProcess/wpe/WebPageProxyWPE.cpp:
(WebKit::WebPageProxy::userAgentForURL): Ditto.

Tools:

Add unit tests to check the user agent is sent in headers and preserved after a redirect for both main resource
and subresources.

* TestWebKitAPI/Tests/WebKitGLib/TestDownloads.cpp:
(serverCallback):
(testDownloadUserAgent):
(beforeAll):
* TestWebKitAPI/Tests/WebKitGLib/TestLoaderClient.cpp:
(testUserAgent):
(serverCallback):
(beforeAll):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (266575 => 266576)


--- trunk/Source/WebKit/ChangeLog	2020-09-04 03:07:48 UTC (rev 266575)
+++ trunk/Source/WebKit/ChangeLog	2020-09-04 05:13:53 UTC (rev 266576)
@@ -1,3 +1,32 @@
+2020-09-03  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Unexpected User-Agent on redirect
+        https://bugs.webkit.org/show_bug.cgi?id=191858
+
+        Reviewed by Youenn Fablet.
+
+        Clear the user agent on new request after a redirect to ensure a new one is computed taking into account the
+        quirks if needed. Also ensure quirks are applied for downloads started in the UI process.
+
+        * NetworkProcess/soup/NetworkDataTaskSoup.cpp:
+        (WebKit::NetworkDataTaskSoup::continueHTTPRedirection): Clear the user agent on new request.
+        * UIProcess/API/glib/WebKitDownloadClient.cpp:
+        * UIProcess/WebPageProxy.h: Add userAgentForURL().
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::download): Use userAgentForURL() instead of userAgent().
+        * UIProcess/gtk/WebPageProxyGtk.cpp:
+        (WebKit::WebPageProxy::userAgentForURL): Implement it to apply quirks if needed.
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::userAgentForURL): Just return the web page user agent.
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::WebPageProxy::userAgentForURL): Ditto.
+        * UIProcess/playstation/WebPageProxyPlayStation.cpp:
+        (WebKit::WebPageProxy::userAgentForURL): Ditto.
+        * UIProcess/win/WebPageProxyWin.cpp:
+        (WebKit::WebPageProxy::userAgentForURL): Ditto.
+        * UIProcess/wpe/WebPageProxyWPE.cpp:
+        (WebKit::WebPageProxy::userAgentForURL): Ditto.
+
 2020-09-02  Darin Adler  <da...@apple.com>
 
         Remove EAffinity, UPSTREAM, DOWNSTREAM, SEL_DEFAULT_AFFINITY, and VisibleSelection::selectionType

Modified: trunk/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp (266575 => 266576)


--- trunk/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp	2020-09-04 03:07:48 UTC (rev 266575)
+++ trunk/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp	2020-09-04 05:13:53 UTC (rev 266576)
@@ -671,6 +671,10 @@
         redirectedURL.setFragmentIdentifier(request.url().fragmentIdentifier());
     request.setURL(redirectedURL);
 
+    // Clear the user agent to ensure a new one is computed.
+    auto userAgent = request.httpUserAgent();
+    request.clearHTTPUserAgent();
+
     // Should not set Referer after a redirect from a secure resource to non-secure one.
     if (m_shouldClearReferrerOnHTTPSToHTTPRedirect && !request.url().protocolIs("https") && protocolIs(request.httpReferrer(), "https"))
         request.clearHTTPReferrer();
@@ -723,7 +727,7 @@
     clearRequest();
 
     auto response = ResourceResponse(m_response);
-    m_client->willPerformHTTPRedirection(WTFMove(response), WTFMove(request), [this, protectedThis = makeRef(*this), isCrossOrigin, wasBlockingCookies](const ResourceRequest& newRequest) {
+    m_client->willPerformHTTPRedirection(WTFMove(response), WTFMove(request), [this, protectedThis = makeRef(*this), isCrossOrigin, wasBlockingCookies, userAgent = WTFMove(userAgent)](const ResourceRequest& newRequest) {
         if (newRequest.isNull() || m_state == State::Canceling)
             return;
 
@@ -735,6 +739,9 @@
             }
 
             applyAuthenticationToRequest(request);
+
+            if (!request.hasHTTPHeaderField(HTTPHeaderName::UserAgent))
+                request.setHTTPUserAgent(userAgent);
         }
         createRequest(WTFMove(request), wasBlockingCookies);
         if (m_soupRequest && m_state != State::Suspended) {

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


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitDownloadClient.cpp	2020-09-04 03:07:48 UTC (rev 266575)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitDownloadClient.cpp	2020-09-04 05:13:53 UTC (rev 266576)
@@ -26,6 +26,7 @@
 #include "WebKitWebContextPrivate.h"
 #include "WebKitWebViewPrivate.h"
 #include "WebsiteDataStore.h"
+#include <WebCore/UserAgent.h>
 #include <wtf/glib/GRefPtr.h>
 #include <wtf/text/CString.h>
 
@@ -47,6 +48,17 @@
         webkitWebContextDownloadStarted(m_webContext, download.get());
     }
 
+    void willSendRequest(DownloadProxy& downloadProxy, ResourceRequest&& request, const ResourceResponse&, CompletionHandler<void(ResourceRequest&&)>&& completionHandler) override
+    {
+        if (!request.hasHTTPHeaderField(HTTPHeaderName::UserAgent)) {
+            GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(&downloadProxy);
+            auto* webView = webkit_download_get_web_view(download.get());
+            request.setHTTPUserAgent(webView ? webkitWebViewGetPage(webView).userAgentForURL(request.url()) : WebPageProxy::standardUserAgent());
+        }
+
+        completionHandler(WTFMove(request));
+    }
+
     void didReceiveAuthenticationChallenge(DownloadProxy& downloadProxy, AuthenticationChallengeProxy& authenticationChallenge) override
     {
         GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(&downloadProxy);

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (266575 => 266576)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2020-09-04 03:07:48 UTC (rev 266575)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2020-09-04 05:13:53 UTC (rev 266576)
@@ -975,6 +975,7 @@
     const String& toolTip() const { return m_toolTip; }
 
     const String& userAgent() const { return m_userAgent; }
+    String userAgentForURL(const URL&);
     void setApplicationNameForUserAgent(const String&);
     const String& applicationNameForUserAgent() const { return m_applicationNameForUserAgent; }
     void setApplicationNameForDesktopUserAgent(const String& applicationName) { m_applicationNameForDesktopUserAgent = applicationName; }

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (266575 => 266576)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2020-09-04 03:07:48 UTC (rev 266575)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2020-09-04 05:13:53 UTC (rev 266576)
@@ -1426,7 +1426,7 @@
             updatedRequest.setFirstPartyForCookies(initiatingPageURL);
             updatedRequest.setIsSameSite(areRegistrableDomainsEqual(initiatingPageURL, request.url()));
             if (!updatedRequest.hasHTTPHeaderField(HTTPHeaderName::UserAgent))
-                updatedRequest.setHTTPUserAgent(initiatingPage->userAgent());
+                updatedRequest.setHTTPUserAgent(initiatingPage->userAgentForURL(request.url()));
         } else {
             updatedRequest.setFirstPartyForCookies(URL());
             updatedRequest.setIsSameSite(false);

Modified: trunk/Source/WebKit/UIProcess/gtk/WebPageProxyGtk.cpp (266575 => 266576)


--- trunk/Source/WebKit/UIProcess/gtk/WebPageProxyGtk.cpp	2020-09-04 03:07:48 UTC (rev 266575)
+++ trunk/Source/WebKit/UIProcess/gtk/WebPageProxyGtk.cpp	2020-09-04 05:13:53 UTC (rev 266576)
@@ -52,6 +52,15 @@
     return static_cast<PageClientImpl&>(pageClient()).viewWidget();
 }
 
+String WebPageProxy::userAgentForURL(const URL& url)
+{
+    if (url.isNull() || !preferences().needsSiteSpecificQuirks())
+        return this->userAgent();
+
+    auto userAgent = WebCore::standardUserAgentForURL(url);
+    return userAgent.isNull() ? this->userAgent() : userAgent;
+}
+
 String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
 {
     return WebCore::standardUserAgent(applicationNameForUserAgent);

Modified: trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm (266575 => 266576)


--- trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm	2020-09-04 03:07:48 UTC (rev 266575)
+++ trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm	2020-09-04 05:13:53 UTC (rev 266576)
@@ -90,6 +90,11 @@
 {
 }
 
+String WebPageProxy::userAgentForURL(const URL&)
+{
+    return userAgent();
+}
+
 String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
 {
     return standardUserAgentWithApplicationName(applicationNameForUserAgent);

Modified: trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm (266575 => 266576)


--- trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm	2020-09-04 03:07:48 UTC (rev 266575)
+++ trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm	2020-09-04 05:13:53 UTC (rev 266576)
@@ -129,6 +129,11 @@
     setShouldUseImplicitRubberBandControl(clientExpectsLegacyImplicitRubberBandControl);
 }
 
+String WebPageProxy::userAgentForURL(const URL&)
+{
+    return userAgent();
+}
+
 String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
 {
     return standardUserAgentWithApplicationName(applicationNameForUserAgent);

Modified: trunk/Source/WebKit/UIProcess/playstation/WebPageProxyPlayStation.cpp (266575 => 266576)


--- trunk/Source/WebKit/UIProcess/playstation/WebPageProxyPlayStation.cpp	2020-09-04 03:07:48 UTC (rev 266575)
+++ trunk/Source/WebKit/UIProcess/playstation/WebPageProxyPlayStation.cpp	2020-09-04 05:13:53 UTC (rev 266576)
@@ -43,6 +43,11 @@
     return nullptr;
 }
 
+String WebPageProxy::userAgentForURL(const URL&)
+{
+    return userAgent();
+}
+
 String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
 {
     return WebCore::standardUserAgent(applicationNameForUserAgent);

Modified: trunk/Source/WebKit/UIProcess/win/WebPageProxyWin.cpp (266575 => 266576)


--- trunk/Source/WebKit/UIProcess/win/WebPageProxyWin.cpp	2020-09-04 03:07:48 UTC (rev 266575)
+++ trunk/Source/WebKit/UIProcess/win/WebPageProxyWin.cpp	2020-09-04 05:13:53 UTC (rev 266576)
@@ -42,6 +42,11 @@
 {
 }
 
+String WebPageProxy::userAgentForURL(const URL&)
+{
+    return userAgent();
+}
+
 String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
 {
     return WebCore::standardUserAgent(applicationNameForUserAgent);

Modified: trunk/Source/WebKit/UIProcess/wpe/WebPageProxyWPE.cpp (266575 => 266576)


--- trunk/Source/WebKit/UIProcess/wpe/WebPageProxyWPE.cpp	2020-09-04 03:07:48 UTC (rev 266575)
+++ trunk/Source/WebKit/UIProcess/wpe/WebPageProxyWPE.cpp	2020-09-04 05:13:53 UTC (rev 266576)
@@ -49,6 +49,11 @@
     return static_cast<PageClientImpl&>(pageClient()).viewBackend();
 }
 
+String WebPageProxy::userAgentForURL(const URL&)
+{
+    return userAgent();
+}
+
 String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
 {
     return WebCore::standardUserAgent(applicationNameForUserAgent);

Modified: trunk/Tools/ChangeLog (266575 => 266576)


--- trunk/Tools/ChangeLog	2020-09-04 03:07:48 UTC (rev 266575)
+++ trunk/Tools/ChangeLog	2020-09-04 05:13:53 UTC (rev 266576)
@@ -1,3 +1,22 @@
+2020-09-03  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Unexpected User-Agent on redirect
+        https://bugs.webkit.org/show_bug.cgi?id=191858
+
+        Reviewed by Youenn Fablet.
+
+        Add unit tests to check the user agent is sent in headers and preserved after a redirect for both main resource
+        and subresources.
+
+        * TestWebKitAPI/Tests/WebKitGLib/TestDownloads.cpp:
+        (serverCallback):
+        (testDownloadUserAgent):
+        (beforeAll):
+        * TestWebKitAPI/Tests/WebKitGLib/TestLoaderClient.cpp:
+        (testUserAgent):
+        (serverCallback):
+        (beforeAll):
+
 2020-09-02  Ryosuke Niwa  <rn...@webkit.org>
 
         Add CompactUniquePtrTuple

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestDownloads.cpp (266575 => 266576)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestDownloads.cpp	2020-09-04 03:07:48 UTC (rev 266575)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestDownloads.cpp	2020-09-04 05:13:53 UTC (rev 266576)
@@ -379,6 +379,7 @@
 
 static WebKitTestServer* kServer;
 static const char* kServerSuggestedFilename = "webkit-downloaded-file";
+static HashMap<CString, CString> s_userAgentMap;
 
 static void addContentDispositionHTTPHeaderToResponse(SoupMessage* message)
 {
@@ -408,6 +409,9 @@
 
     soup_message_set_status(message, SOUP_STATUS_OK);
 
+    if (g_str_has_prefix(path, "/ua-"))
+        s_userAgentMap.add(path, soup_message_headers_get_one(message->request_headers, "User-Agent"));
+
     if (g_str_equal(path, "/cancel-after-destination")) {
         // Use an infinite message to make sure it's cancelled before it finishes.
         soup_message_headers_set_encoding(message->response_headers, SOUP_ENCODING_CHUNKED);
@@ -417,7 +421,13 @@
         return;
     }
 
-    if (g_str_equal(path, "/unknown"))
+    if (g_str_equal(path, "/ua-test-redirect")) {
+        soup_message_set_status(message, SOUP_STATUS_MOVED_PERMANENTLY);
+        soup_message_headers_append(message->response_headers, "Location", "/ua-test");
+        return;
+    }
+
+    if (g_str_equal(path, "/unknown") || g_str_equal(path, "/ua-test"))
         path = "/test.pdf";
 
     GUniquePtr<char> filePath(g_build_filename(Test::getResourcesDir().data(), path, nullptr));
@@ -721,6 +731,43 @@
     test->checkDestinationAndDeleteFile(download.get(), expectedFilename.get());
 }
 
+static void testDownloadUserAgent(DownloadTest* test, gconstpointer)
+{
+    s_userAgentMap.clear();
+    GRefPtr<WebKitDownload> download = test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/ua-test"));
+    g_assert_null(webkit_download_get_web_view(download.get()));
+    WebKitURIRequest* request = webkit_download_get_request(download.get());
+    g_assert_true(WEBKIT_IS_URI_REQUEST(request));
+    ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, kServer->getURIForPath("/ua-test"));
+
+    const char* userAgent = soup_message_headers_get_one(webkit_uri_request_get_http_headers(request), "User-Agent");
+    g_assert_nonnull(userAgent);
+    g_assert_cmpuint(s_userAgentMap.size(), ==, 1);
+    g_assert_true(s_userAgentMap.contains("/ua-test"));
+    ASSERT_CMP_CSTRING(userAgent, ==, s_userAgentMap.get("/ua-test"));
+    s_userAgentMap.clear();
+
+    GUniquePtr<char> expectedFilename(g_strdup_printf("%s.pdf", kServerSuggestedFilename));
+    test->checkDestinationAndDeleteFile(download.get(), expectedFilename.get());
+
+    download = test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/ua-test-redirect"));
+    g_assert_null(webkit_download_get_web_view(download.get()));
+    request = webkit_download_get_request(download.get());
+    g_assert_true(WEBKIT_IS_URI_REQUEST(request));
+    ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, kServer->getURIForPath("/ua-test-redirect"));
+
+    userAgent = soup_message_headers_get_one(webkit_uri_request_get_http_headers(request), "User-Agent");
+    g_assert_nonnull(userAgent);
+    g_assert_cmpuint(s_userAgentMap.size(), ==, 2);
+    g_assert_true(s_userAgentMap.contains("/ua-test-redirect"));
+    ASSERT_CMP_CSTRING(userAgent, ==, s_userAgentMap.get("/ua-test-redirect"));
+    g_assert_true(s_userAgentMap.contains("/ua-test"));
+    ASSERT_CMP_CSTRING(userAgent, ==, s_userAgentMap.get("/ua-test"));
+    s_userAgentMap.clear();
+
+    test->checkDestinationAndDeleteFile(download.get(), expectedFilename.get());
+}
+
 #if PLATFORM(GTK)
 static void testContextMenuDownloadActions(WebViewDownloadTest* test, gconstpointer)
 {
@@ -805,6 +852,7 @@
     PolicyResponseDownloadTest::add("Downloads", "policy-decision-download", testPolicyResponseDownload);
     PolicyResponseDownloadTest::add("Downloads", "policy-decision-download-cancel", testPolicyResponseDownloadCancel);
     DownloadTest::add("Downloads", "mime-type", testDownloadMIMEType);
+    DownloadTest::add("Downloads", "user-agent", testDownloadUserAgent);
     // FIXME: Implement keyStroke in WPE.
 #if PLATFORM(GTK)
 #if !USE(GTK4)

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestLoaderClient.cpp (266575 => 266576)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestLoaderClient.cpp	2020-09-04 03:07:48 UTC (rev 266575)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestLoaderClient.cpp	2020-09-04 05:13:53 UTC (rev 266576)
@@ -693,6 +693,50 @@
     g_assert_cmpint(strncmp(mainResourceData, expectedData, mainResourceDataSize), ==, 0);
 }
 
+static HashMap<CString, CString> s_userAgentMap;
+
+static void testUserAgent(WebViewTest* test, gconstpointer)
+{
+    const char* userAgent = webkit_settings_get_user_agent(webkit_web_view_get_settings(test->m_webView));
+
+    s_userAgentMap.clear();
+    test->loadURI(kServer->getURIForPath("/ua-main").data());
+    test->waitUntilLoadFinished();
+    g_assert_cmpuint(s_userAgentMap.size(), ==, 1);
+    g_assert_true(s_userAgentMap.contains("/ua-main"));
+    ASSERT_CMP_CSTRING(userAgent, ==, s_userAgentMap.get("/ua-main"));
+    s_userAgentMap.clear();
+
+    test->loadURI(kServer->getURIForPath("/ua-main-redirect").data());
+    test->waitUntilLoadFinished();
+    g_assert_cmpuint(s_userAgentMap.size(), ==, 2);
+    g_assert_true(s_userAgentMap.contains("/ua-main-redirect"));
+    ASSERT_CMP_CSTRING(userAgent, ==, s_userAgentMap.get("/ua-main-redirect"));
+    g_assert_true(s_userAgentMap.contains("/ua-main"));
+    ASSERT_CMP_CSTRING(userAgent, ==, s_userAgentMap.get("/ua-main"));
+    s_userAgentMap.clear();
+
+    test->loadURI(kServer->getURIForPath("/ua-css").data());
+    test->waitUntilLoadFinished();
+    g_assert_cmpuint(s_userAgentMap.size(), ==, 2);
+    g_assert_true(s_userAgentMap.contains("/ua-css"));
+    ASSERT_CMP_CSTRING(userAgent, ==, s_userAgentMap.get("/ua-css"));
+    g_assert_true(s_userAgentMap.contains("/ua-style.css"));
+    ASSERT_CMP_CSTRING(userAgent, ==, s_userAgentMap.get("/ua-style.css"));
+    s_userAgentMap.clear();
+
+    test->loadURI(kServer->getURIForPath("/ua-redirected-css").data());
+    test->waitUntilLoadFinished();
+    g_assert_cmpuint(s_userAgentMap.size(), ==, 3);
+    g_assert_true(s_userAgentMap.contains("/ua-redirected-css"));
+    ASSERT_CMP_CSTRING(userAgent, ==, s_userAgentMap.get("/ua-redirected-css"));
+    g_assert_true(s_userAgentMap.contains("/ua-redirected-style.css"));
+    ASSERT_CMP_CSTRING(userAgent, ==, s_userAgentMap.get("/ua-redirected-style.css"));
+    g_assert_true(s_userAgentMap.contains("/ua-style.css"));
+    ASSERT_CMP_CSTRING(userAgent, ==, s_userAgentMap.get("/ua-style.css"));
+    s_userAgentMap.clear();
+}
+
 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!"
@@ -711,6 +755,9 @@
 
     soup_message_set_status(message, SOUP_STATUS_OK);
 
+    if (g_str_has_prefix(path, "/ua-"))
+        s_userAgentMap.add(path, soup_message_headers_get_one(message->request_headers, "User-Agent"));
+
     if (g_str_has_prefix(path, "/normal") || g_str_has_prefix(path, "/http-get-method"))
         soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, responseString, strlen(responseString));
     else if (g_str_equal(path, "/error"))
@@ -754,6 +801,23 @@
             "</script>"
             "</body></html>";
         soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, unfinishedSubresourceLoadResponseString, strlen(unfinishedSubresourceLoadResponseString));
+    } else if (g_str_equal(path, "/ua-main"))
+        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, responseString, strlen(responseString));
+    else if (g_str_equal(path, "/ua-main-redirect")) {
+        soup_message_headers_append(message->response_headers, "Location", "/ua-main");
+        soup_message_set_status(message, SOUP_STATUS_MOVED_PERMANENTLY);
+    } else if (g_str_equal(path, "/ua-style.css")) {
+        static const char* style = "body { margin: 0px; padding: 0px; }";
+        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, style, strlen(style));
+    } else if (g_str_equal(path, "/ua-redirected-style.css")) {
+        soup_message_headers_append(message->response_headers, "Location", "/ua-style.css");
+        soup_message_set_status(message, SOUP_STATUS_MOVED_PERMANENTLY);
+    } else if (g_str_equal(path, "/ua-css")) {
+        static const char* cssHtml = "<html><head><link rel='stylesheet' href='' type='text/css'></head><body></html>";
+        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, cssHtml, strlen(cssHtml));
+    } else if (g_str_equal(path, "/ua-redirected-css")) {
+        static const char* redirectedCSSHtml = "<html><head><link rel='stylesheet' href='' type='text/css'></head><body></html>";
+        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, redirectedCSSHtml, strlen(redirectedCSSHtml));
     } else if (g_str_equal(path, "/stall")) {
         // This request is never unpaused and stalls forever.
         soup_server_pause_message(server, message);
@@ -796,6 +860,7 @@
     WebViewTest::add("WebKitURIRequest", "http-method", testURIRequestHTTPMethod);
     WebViewTest::add("WebKitURIResponse", "http-headers", testURIResponseHTTPHeaders);
     WebViewTest::add("WebKitWebPage", "redirect-to-data-uri", testRedirectToDataURI);
+    WebViewTest::add("WebKitWebView", "user-agent", testUserAgent);
 }
 
 void afterAll()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to