Bug 143125 - [WK2][NetworkCache] We only cache responses with status codes that are cacheable by default
Summary: [WK2][NetworkCache] We only cache responses with status codes that are cachea...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-03-26 20:01 PDT by Chris Dumez
Modified: 2015-03-27 11:25 PDT (History)
4 users (show)

See Also:


Attachments
Patch (12.23 KB, patch)
2015-03-26 21:46 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (12.23 KB, patch)
2015-03-26 21:48 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (13.15 KB, patch)
2015-03-27 10:22 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (13.18 KB, patch)
2015-03-27 10:36 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2015-03-26 20:01:47 PDT
We currently only cache responses with status codes that are cacheable by default [1]. However, RFC 7234 [2] allows us to cache responses with other status codes, as long as they have explicit headers allowing caching:
- 'Expires' header field
- 'max-age' response directive

[1] http://tools.ietf.org/html/rfc7231#page-48
[2] http://tools.ietf.org/html/rfc7234#section-4.3.2
Comment 1 Radar WebKit Bug Importer 2015-03-26 20:02:10 PDT
<rdar://problem/20321172>
Comment 2 Chris Dumez 2015-03-26 21:46:44 PDT
Created attachment 249550 [details]
Patch
Comment 3 Chris Dumez 2015-03-26 21:48:18 PDT
Created attachment 249551 [details]
Patch
Comment 4 Antti Koivisto 2015-03-27 06:06:37 PDT
Comment on attachment 249551 [details]
Patch

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

> Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp:286
> +    // Check for expiration headers allowing us to cache.
> +    // http://tools.ietf.org/html/rfc7234#section-4.3.2
> +    if (std::isfinite(response.expires()) || std::isfinite(response.cacheControlMaxAge()))
> +        return StoreDecision::Yes;

http://tools.ietf.org/html/rfc7234#section-3

A cache MUST NOT store a response to any request, unless:
- the response status code is understood by the cache, and
- ...

To me this sounds like we might still want to have a list of status codes that we "understand" and not just cache everything with >0 cache lifetime specified in headers. Maybe just a list of all valid status codes.

> Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp:294
>      switch (response.httpStatusCode()) {
> +    // These status codes are cacheable by default:
> +    // http://tools.ietf.org/html/rfc7231#page-48
>      case 200: // OK
>      case 203: // Non-Authoritative Information
>      case 204: // No Content
>      case 300: // Multiple Choices

Would be nice to factor this into a function: isResponseCacheableByDefault(). Then you don't need to write a comment explaining what these are about.
Comment 5 Chris Dumez 2015-03-27 10:22:55 PDT
Created attachment 249579 [details]
Patch
Comment 6 Antti Koivisto 2015-03-27 10:26:54 PDT
Comment on attachment 249579 [details]
Patch

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

> Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp:345
> +    LOG(NetworkCache, "(NetworkProcess) status code %d is not cacheable by default", response.httpStatusCode());

The message is now wrong, you should drop "by default"
Comment 7 Chris Dumez 2015-03-27 10:36:50 PDT
Created attachment 249580 [details]
Patch
Comment 8 WebKit Commit Bot 2015-03-27 11:25:24 PDT
Comment on attachment 249580 [details]
Patch

Clearing flags on attachment: 249580

Committed r182071: <http://trac.webkit.org/changeset/182071>
Comment 9 WebKit Commit Bot 2015-03-27 11:25:30 PDT
All reviewed patches have been landed.  Closing bug.