[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

kocienda kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:18:27 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit ee1d70306e1e2d1addfac5002f3761ea96fc486e
Author: kocienda <kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Dec 11 23:56:37 2003 +0000

            Reviewed by Darin
    
    	Fix for this bug:
    
    	<rdar://problem/3489280>: redirect via post blows cache, causing everything to get reloaded
    
    	Now POST requests reload the main document by default, but will not reload
    	all subresources.
    
            * WebCoreSupport.subproj/WebSubresourceClient.m:
            (+[WebSubresourceClient startLoadingResource:withRequest:customHeaders:referrer:forDataSource:]):
            * WebView.subproj/WebFrame.m:
            (-[WebFrame _postWithURL:referrer:target:data:contentType:triggeringEvent:form:formValues:]):
    	Take the cache policy for subresources from the original request, rather than
    	the data source's current request.
            * WebView.subproj/WebMainResourceClient.m:
            (-[WebMainResourceClient _isPostOrRedirectAfterPost:redirectResponse:]): New helper.
            (-[WebMainResourceClient connection:willSendRequest:redirectResponse:]):
    	Call new helper to set the cache policy on the main resource load.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5773 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index 12b880e..cbd61b6 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,25 @@
+2003-12-11  Ken Kocienda  <kocienda at apple.com>
+
+        Reviewed by Darin
+
+	Fix for this bug:
+
+	<rdar://problem/3489280>: redirect via post blows cache, causing everything to get reloaded
+
+	Now POST requests reload the main document by default, but will not reload 
+	all subresources.
+
+        * WebCoreSupport.subproj/WebSubresourceClient.m:
+        (+[WebSubresourceClient startLoadingResource:withRequest:customHeaders:referrer:forDataSource:]):
+        * WebView.subproj/WebFrame.m:
+        (-[WebFrame _postWithURL:referrer:target:data:contentType:triggeringEvent:form:formValues:]):
+	Take the cache policy for subresources from the original request, rather than
+	the data source's current request. 
+        * WebView.subproj/WebMainResourceClient.m:
+        (-[WebMainResourceClient _isPostOrRedirectAfterPost:redirectResponse:]): New helper.
+        (-[WebMainResourceClient connection:willSendRequest:redirectResponse:]):
+	Call new helper to set the cache policy on the main resource load.
+
 === Safari-117 ===
 
 2003-12-11  Ken Kocienda  <kocienda at apple.com>
diff --git a/WebKit/WebCoreSupport.subproj/WebSubresourceClient.m b/WebKit/WebCoreSupport.subproj/WebSubresourceClient.m
index 684b780..3073b6a 100644
--- a/WebKit/WebCoreSupport.subproj/WebSubresourceClient.m
+++ b/WebKit/WebCoreSupport.subproj/WebSubresourceClient.m
@@ -56,7 +56,13 @@
 	[newRequest addValue:[customHeaders objectForKey:key] forHTTPHeaderField:key];
     }
 
-    [newRequest setCachePolicy:[[source request] cachePolicy]];
+    // Use the original request's cache policy for two reasons:
+    // 1. For POST requests, we mutate the cache policy for the main resource,
+    //    but we do not want this to apply to subresources
+    // 2. Delegates that modify the cache policy using willSendRequest: should
+    //    not affect any other resources. Such changes need to be done
+    //    per request.
+    [newRequest setCachePolicy:[[source _originalRequest] cachePolicy]];
     [newRequest setHTTPReferrer:referrer];
     
     WebView *_webView = [source _webView];
diff --git a/WebKit/WebCoreSupport.subproj/WebSubresourceLoader.m b/WebKit/WebCoreSupport.subproj/WebSubresourceLoader.m
index 684b780..3073b6a 100644
--- a/WebKit/WebCoreSupport.subproj/WebSubresourceLoader.m
+++ b/WebKit/WebCoreSupport.subproj/WebSubresourceLoader.m
@@ -56,7 +56,13 @@
 	[newRequest addValue:[customHeaders objectForKey:key] forHTTPHeaderField:key];
     }
 
-    [newRequest setCachePolicy:[[source request] cachePolicy]];
+    // Use the original request's cache policy for two reasons:
+    // 1. For POST requests, we mutate the cache policy for the main resource,
+    //    but we do not want this to apply to subresources
+    // 2. Delegates that modify the cache policy using willSendRequest: should
+    //    not affect any other resources. Such changes need to be done
+    //    per request.
+    [newRequest setCachePolicy:[[source _originalRequest] cachePolicy]];
     [newRequest setHTTPReferrer:referrer];
     
     WebView *_webView = [source _webView];
diff --git a/WebKit/WebView.subproj/WebFrame.m b/WebKit/WebView.subproj/WebFrame.m
index 84ceb71..ecbe321 100644
--- a/WebKit/WebView.subproj/WebFrame.m
+++ b/WebKit/WebView.subproj/WebFrame.m
@@ -1822,7 +1822,6 @@ static CFAbsoluteTime _timeOfLastCompletedLoad;
     // as an action to be returned from the cache without submitting.
     NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:URL];
     [self _addExtraFieldsToRequest:request alwaysFromRequest: YES];
-    [request setCachePolicy:NSURLRequestReloadIgnoringCacheData];
     [request setHTTPMethod:@"POST"];
     [request setHTTPBody:data];
     [request setHTTPContentType:contentType];
diff --git a/WebKit/WebView.subproj/WebMainResourceClient.m b/WebKit/WebView.subproj/WebMainResourceClient.m
index ccd3ec1..4a5ec44 100644
--- a/WebKit/WebView.subproj/WebMainResourceClient.m
+++ b/WebKit/WebView.subproj/WebMainResourceClient.m
@@ -106,6 +106,24 @@
     }
 }
 
+- (BOOL)_isPostOrRedirectAfterPost:(NSURLRequest *)newRequest redirectResponse:(NSURLResponse *)redirectResponse
+{
+    BOOL result = NO;
+    
+    if ([[newRequest HTTPMethod] isEqualToString:@"POST"]) {
+        result = YES;
+    }
+    else if (redirectResponse && [redirectResponse isKindOfClass:[NSHTTPURLResponse class]]) {
+        int status = [(NSHTTPURLResponse *)redirectResponse statusCode];
+        if (((status >= 301 && status <= 303) || status == 307)
+            && [[[dataSource initialRequest] HTTPMethod] isEqualToString:@"POST"]) {
+            result = YES;
+        }
+    }
+    
+    return result;
+}
+
 - (NSURLRequest *)connection:(NSURLConnection *)con willSendRequest:(NSURLRequest *)newRequest redirectResponse:(NSURLResponse *)redirectResponse
 {
     // Note that there are no asserts here as there are for the other callbacks. This is due to the
@@ -133,16 +151,13 @@
     // If we're fielding a redirect in response to a POST, force a load from origin, since
     // this is a common site technique to return to a page viewing some data that the POST
     // just modified.
-    if (redirectResponse && [redirectResponse isKindOfClass:[NSHTTPURLResponse class]]) {
-        int status = [(NSHTTPURLResponse *)redirectResponse statusCode];
-        if (((status >= 301 && status <= 303) || status == 307)
-            && [[[dataSource initialRequest] HTTPMethod] isEqualToString:@"POST"])
-        {
-            if (!mutableRequest) {
-                mutableRequest = [newRequest mutableCopy];
-            }
-            [mutableRequest setCachePolicy:NSURLRequestReloadIgnoringCacheData];
+    // Also, POST requests always load from origin, but this does not affect subresources.
+    if ([newRequest cachePolicy] == NSURLRequestUseProtocolCachePolicy && 
+        [self _isPostOrRedirectAfterPost:newRequest redirectResponse:redirectResponse]) {
+        if (!mutableRequest) {
+            mutableRequest = [newRequest mutableCopy];
         }
+        [mutableRequest setCachePolicy:NSURLRequestReloadIgnoringCacheData];
     }
     if (mutableRequest) {
         newRequest = [mutableRequest autorelease];
diff --git a/WebKit/WebView.subproj/WebMainResourceLoader.m b/WebKit/WebView.subproj/WebMainResourceLoader.m
index ccd3ec1..4a5ec44 100644
--- a/WebKit/WebView.subproj/WebMainResourceLoader.m
+++ b/WebKit/WebView.subproj/WebMainResourceLoader.m
@@ -106,6 +106,24 @@
     }
 }
 
+- (BOOL)_isPostOrRedirectAfterPost:(NSURLRequest *)newRequest redirectResponse:(NSURLResponse *)redirectResponse
+{
+    BOOL result = NO;
+    
+    if ([[newRequest HTTPMethod] isEqualToString:@"POST"]) {
+        result = YES;
+    }
+    else if (redirectResponse && [redirectResponse isKindOfClass:[NSHTTPURLResponse class]]) {
+        int status = [(NSHTTPURLResponse *)redirectResponse statusCode];
+        if (((status >= 301 && status <= 303) || status == 307)
+            && [[[dataSource initialRequest] HTTPMethod] isEqualToString:@"POST"]) {
+            result = YES;
+        }
+    }
+    
+    return result;
+}
+
 - (NSURLRequest *)connection:(NSURLConnection *)con willSendRequest:(NSURLRequest *)newRequest redirectResponse:(NSURLResponse *)redirectResponse
 {
     // Note that there are no asserts here as there are for the other callbacks. This is due to the
@@ -133,16 +151,13 @@
     // If we're fielding a redirect in response to a POST, force a load from origin, since
     // this is a common site technique to return to a page viewing some data that the POST
     // just modified.
-    if (redirectResponse && [redirectResponse isKindOfClass:[NSHTTPURLResponse class]]) {
-        int status = [(NSHTTPURLResponse *)redirectResponse statusCode];
-        if (((status >= 301 && status <= 303) || status == 307)
-            && [[[dataSource initialRequest] HTTPMethod] isEqualToString:@"POST"])
-        {
-            if (!mutableRequest) {
-                mutableRequest = [newRequest mutableCopy];
-            }
-            [mutableRequest setCachePolicy:NSURLRequestReloadIgnoringCacheData];
+    // Also, POST requests always load from origin, but this does not affect subresources.
+    if ([newRequest cachePolicy] == NSURLRequestUseProtocolCachePolicy && 
+        [self _isPostOrRedirectAfterPost:newRequest redirectResponse:redirectResponse]) {
+        if (!mutableRequest) {
+            mutableRequest = [newRequest mutableCopy];
         }
+        [mutableRequest setCachePolicy:NSURLRequestReloadIgnoringCacheData];
     }
     if (mutableRequest) {
         newRequest = [mutableRequest autorelease];

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list