Bug 158256

Summary: Speculative revalidated request returns 200 instead of 304
Product: WebKit Reporter: Carlos Garcia Campos <cgarcia>
Component: WebKit2Assignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: bugs-noreply, cdumez, koivisto
Priority: P2    
Version: WebKit Local Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch cgarcia: review+

Description Carlos Garcia Campos 2016-06-01 02:31:39 PDT
I noticed that after enabling speculative revalidation in the GTk+ port the unit test /webkit2/WebKitWebResource/response started to fail in the bots:

  /webkit2/WebKitWebResource/response:                                 **

ERROR:../../Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestResources.cpp:417:void testWebResourceResponse(SingleResourceLoadTest*, gconstpointer): assertion failed (webkit_uri_response_get_status_code(response) == SOUP_STATUS_NOT_MODIFIED): (200 == 304)

FAIL

We are simply doing a reload and checking that the response code we get for a subresource is 304, but now is 200, because the network process is using a preloaded entry. I would expect that in case of successful speculative revalidation, 304 was returned like a normal revalidation request, and the resource be loaded from the memory cache.
Comment 1 Chris Dumez 2016-06-01 09:35:26 PDT
I am investigating but I will likely need help testing a fix.
Comment 2 Chris Dumez 2016-06-01 09:52:02 PDT
Created attachment 280244 [details]
Patch
Comment 3 Chris Dumez 2016-06-01 10:10:33 PDT
Created attachment 280245 [details]
Patch
Comment 4 Chris Dumez 2016-06-01 10:11:00 PDT
Comment on attachment 280245 [details]
Patch

Carlos, could you confirm this fixes the GTK unit test?
Comment 5 Chris Dumez 2016-06-01 18:25:57 PDT
Created attachment 280290 [details]
Patch
Comment 6 Carlos Garcia Campos 2016-06-02 00:39:53 PDT
(In reply to comment #4)
> Comment on attachment 280245 [details]
> Patch
> 
> Carlos, could you confirm this fixes the GTK unit test?

/webkit2/WebKitWebResource/response: OK

Yes, thanks for the quick fix!
Comment 7 Carlos Garcia Campos 2016-06-02 00:42:32 PDT
Comment on attachment 280290 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=280290&action=review

Patch looks good to me. I'm not wk2 owner so please, wait until an owner approves this before cq+ it. Thanks!

> Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp:278
> -    static const HTTPHeaderName headersAllowedToMismatch[] = {
> -        HTTPHeaderName::IfMatch,
> -        HTTPHeaderName::IfModifiedSince,
> -        HTTPHeaderName::IfNoneMatch,
> -        HTTPHeaderName::IfRange,
> -        HTTPHeaderName::IfUnmodifiedSince,
> -        HTTPHeaderName::CacheControl
> -    };
> -
> -    HTTPHeaderMap headersA = a.httpHeaderFields();
> -    HTTPHeaderMap headersB = b.httpHeaderFields();
> -    for (auto headerName : headersAllowedToMismatch) {
> -        headersA.remove(headerName);
> -        headersB.remove(headerName);
> -    }
> +    ASSERT(!actualRequest.isConditional());
> +    ResourceRequest speculativeRequest = speculativeValidationRequest;
> +    speculativeRequest.makeUnconditional();
>  
> -    if (headersA != headersB) {
> +    if (speculativeRequest.httpHeaderFields() != actualRequest.httpHeaderFields()) {

Nice cleanup!
Comment 8 Antti Koivisto 2016-06-02 01:52:51 PDT
Comment on attachment 280290 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=280290&action=review

Looks good

> Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp:-280
> -        HTTPHeaderName::CacheControl

Why no allow CacheControl mismatch? Wouldn't that disallow some cases that would be fine to use?
Comment 9 Chris Dumez 2016-06-02 09:23:14 PDT
(In reply to comment #8)
> Comment on attachment 280290 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=280290&action=review
> 
> Looks good
> 
> > Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp:-280
> > -        HTTPHeaderName::CacheControl
> 
> Why no allow CacheControl mismatch? Wouldn't that disallow some cases that
> would be fine to use?

CacheControl on requests is very rarely used. The only reason I had this code was for the reload case because WebCore sets a "Cache-Control: max-age=0" in some cases. Right now, there is no way WebCore sets "Cache-Control: max-age=0" without also setting conditional headers so keeping this code won't normally help. It could in theory be useful for XHR requests but I doubt Cache-Control is used a lot there. We can add it back if we see XHR requests using Cache-Control header.
Comment 10 Chris Dumez 2016-06-02 09:38:47 PDT
Committed r201600: <http://trac.webkit.org/changeset/201600>