Title: [263548] trunk
Revision
263548
Author
[email protected]
Date
2020-06-25 18:03:22 -0700 (Thu, 25 Jun 2020)

Log Message

REGRESSION(r256166, r260596) WKNavigationAction.request.allHTTPHeaderFields needs to contain User-Agent and Accept
https://bugs.webkit.org/show_bug.cgi?id=213626
<rdar://problem/62374208>

Patch by Alex Christensen <[email protected]> on 2020-06-25
Reviewed by Darin Adler.

Source/WebCore:

Those two revisions seemed to just subtly move things around, but they caused API-breaking changes that caused real problems.
This effectively reverts the parts of those changes that caused the breakages.

* loader/FrameLoader.cpp:
(WebCore::FrameLoader::addExtraFieldsToRequest):
* loader/cache/CachedResourceRequest.cpp:
(WebCore::CachedResourceRequest::acceptHeaderValueFromType):
(WebCore::acceptHeaderValueFromType): Deleted.
* loader/cache/CachedResourceRequest.h:

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm:
(TEST):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (263547 => 263548)


--- trunk/Source/WebCore/ChangeLog	2020-06-26 00:10:25 UTC (rev 263547)
+++ trunk/Source/WebCore/ChangeLog	2020-06-26 01:03:22 UTC (rev 263548)
@@ -1,3 +1,21 @@
+2020-06-25  Alex Christensen  <[email protected]>
+
+        REGRESSION(r256166, r260596) WKNavigationAction.request.allHTTPHeaderFields needs to contain User-Agent and Accept
+        https://bugs.webkit.org/show_bug.cgi?id=213626
+        <rdar://problem/62374208>
+
+        Reviewed by Darin Adler.
+
+        Those two revisions seemed to just subtly move things around, but they caused API-breaking changes that caused real problems.
+        This effectively reverts the parts of those changes that caused the breakages.
+
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::addExtraFieldsToRequest):
+        * loader/cache/CachedResourceRequest.cpp:
+        (WebCore::CachedResourceRequest::acceptHeaderValueFromType):
+        (WebCore::acceptHeaderValueFromType): Deleted.
+        * loader/cache/CachedResourceRequest.h:
+
 2020-06-25  Simon Fraser  <[email protected]>
 
         Convert the PaintLayerFlag enum to an enum class

Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (263547 => 263548)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2020-06-26 00:10:25 UTC (rev 263547)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2020-06-26 01:03:22 UTC (rev 263548)
@@ -2938,6 +2938,11 @@
     // Make sure we send the Origin header.
     addHTTPOriginIfNeeded(request, String());
 
+    applyUserAgentIfNeeded(request);
+
+    if (isMainResource)
+        request.setHTTPHeaderField(HTTPHeaderName::Accept, CachedResourceRequest::acceptHeaderValueFromType(CachedResource::Type::MainResource));
+
     // Only set fallback array if it's still empty (later attempts may be incorrect, see bug 117818).
     if (request.responseContentDispositionEncodingFallbackArray().isEmpty()) {
         // Always try UTF-8. If that fails, try frame encoding (if any) and then the default.

Modified: trunk/Source/WebCore/loader/cache/CachedResourceRequest.cpp (263547 => 263548)


--- trunk/Source/WebCore/loader/cache/CachedResourceRequest.cpp	2020-06-26 00:10:25 UTC (rev 263547)
+++ trunk/Source/WebCore/loader/cache/CachedResourceRequest.cpp	2020-06-26 01:03:22 UTC (rev 263548)
@@ -135,7 +135,7 @@
     #undef WEBP_HEADER_PART
 }
 
-static inline String acceptHeaderValueFromType(CachedResource::Type type)
+String CachedResourceRequest::acceptHeaderValueFromType(CachedResource::Type type)
 {
     switch (type) {
     case CachedResource::Type::MainResource:

Modified: trunk/Source/WebCore/loader/cache/CachedResourceRequest.h (263547 => 263548)


--- trunk/Source/WebCore/loader/cache/CachedResourceRequest.h	2020-06-26 00:10:25 UTC (rev 263547)
+++ trunk/Source/WebCore/loader/cache/CachedResourceRequest.h	2020-06-26 01:03:22 UTC (rev 263548)
@@ -102,6 +102,7 @@
     void clearFragmentIdentifier() { m_fragmentIdentifier = { }; }
 
     static String splitFragmentIdentifierFromRequestURL(ResourceRequest&);
+    static String acceptHeaderValueFromType(CachedResource::Type);
 
 #if ENABLE(SERVICE_WORKER)
     void setClientIdentifierIfNeeded(DocumentIdentifier);

Modified: trunk/Tools/ChangeLog (263547 => 263548)


--- trunk/Tools/ChangeLog	2020-06-26 00:10:25 UTC (rev 263547)
+++ trunk/Tools/ChangeLog	2020-06-26 01:03:22 UTC (rev 263548)
@@ -1,3 +1,14 @@
+2020-06-25  Alex Christensen  <[email protected]>
+
+        REGRESSION(r256166, r260596) WKNavigationAction.request.allHTTPHeaderFields needs to contain User-Agent and Accept
+        https://bugs.webkit.org/show_bug.cgi?id=213626
+        <rdar://problem/62374208>
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm:
+        (TEST):
+
 2020-06-25  Jer Noble  <[email protected]>
 
         iOS Safari incorrectly reports "AppleCoreMedia" as UA string

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm (263547 => 263548)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm	2020-06-26 00:10:25 UTC (rev 263547)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm	2020-06-26 01:03:22 UTC (rev 263548)
@@ -121,6 +121,27 @@
     TestWebKitAPI::Util::run(&done);
 }
 
+#if HAVE(NETWORK_FRAMEWORK)
+TEST(WKNavigation, UserAgentAndAccept)
+{
+    using namespace TestWebKitAPI;
+    HTTPServer server([](Connection) { });
+    __block bool done = false;
+    auto delegate = adoptNS([TestNavigationDelegate new]);
+    delegate.get().decidePolicyForNavigationAction = ^(WKNavigationAction *action, void (^decisionHandler)(WKNavigationActionPolicy)) {
+        EXPECT_WK_STREQ(action.request.allHTTPHeaderFields[@"User-Agent"], "testUserAgent");
+        EXPECT_WK_STREQ(action.request.allHTTPHeaderFields[@"Accept"], "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
+        decisionHandler(WKNavigationActionPolicyCancel);
+        done = true;
+    };
+    auto webView = adoptNS([WKWebView new]);
+    webView.get().customUserAgent = @"testUserAgent";
+    [webView setNavigationDelegate:delegate.get()];
+    [webView loadRequest:server.request()];
+    TestWebKitAPI::Util::run(&done);
+}
+#endif
+
 @interface FrameNavigationDelegate : NSObject <WKNavigationDelegate>
 - (void)waitForNavigations:(size_t)count;
 @property (nonatomic, readonly) NSArray<NSURLRequest *> *requests;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to