Bug 244000

Summary: NetworkCache uses URL instead of URI as a part of caching key
Product: WebKit Reporter: cathiechen <cathiechen>
Component: HistoryAssignee: cathiechen <cathiechen>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, cathiechen, cdumez, cgarcia, ews-watchlist, koivisto, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
WIP-patch ews-feeder: commit-queue-

Description cathiechen 2022-08-16 11:07:12 PDT
Per [1], the key is composed of, at a minimum, the request method and target URI. But in NetworkCache, Cache::makeCacheKey uses URL instead.

We have a test to reproduce that the cache does not work:
  - Open [2] and click the button to add fragment to the URL, then click the link on the page.
  - Terminate safari and reopen it.
  - Hit back button. The page is downloaded from network instead of disk.

Because the browser is terminated, there is no page cache after reopen. Then it goes to network process to get the data, it checks the NetworkCache first,
but there is no entry found for the key does not match. It stores by "https://perfect-lively-xylophone.glitch.me/", but when retrieve, the key is "https://perfect-lively-xylophone.glitch.me/#somefragment".

Not sure if we could treat this key same as the http cache[1], but "fragment identifiers are reserved for client-side processing".
Looks like the cache should be reused.

[1] https://httpwg.org/specs/rfc9111.html#caching.overview
[2] https://perfect-lively-xylophone.glitch.me/
Comment 1 cathiechen 2022-08-16 11:15:34 PDT
Created attachment 461679 [details]
WIP-patch

Upload a WIP patch which use url().stringWithoutFragmentIdentifier() instead of url() as the key.
Comment 2 Alex Christensen 2022-08-16 14:39:46 PDT
This seems like a reasonable change, but needs a test.
Comment 3 Alex Christensen 2022-08-16 14:55:48 PDT
There may be something in LayoutTests/http/tests/cache that is similar to a test we would want for this.
Comment 4 cathiechen 2022-08-18 10:06:43 PDT
Pull request: https://github.com/WebKit/WebKit/pull/3458
Comment 5 cathiechen 2022-08-18 10:13:02 PDT
(In reply to Alex Christensen from comment #3)
> There may be something in LayoutTests/http/tests/cache that is similar to a
> test we would want for this.

Thanks a lot, Alex!
I added a function to generate fragment in LayoutTests/http/tests/cache/disk-cache/resources/cache-test.js
Please take a look at the pull request:)
Comment 6 EWS 2022-08-18 11:30:14 PDT
Committed 253567@main (d62692ae68ab): <https://commits.webkit.org/253567@main>

Reviewed commits have been landed. Closing PR #3458 and removing active labels.
Comment 7 Radar WebKit Bug Importer 2022-08-18 11:31:18 PDT
<rdar://problem/98841865>