Skip to content

Commit

Permalink
Bug 1690306 [wpt PR 27444] - Resolve Service Worker redirects based o…
Browse files Browse the repository at this point in the history
…n the response, a=testonly

Automatic update from web-platform-tests
Resolve Service Worker redirects based on the response

We currently resolve Service-Worker-forwarded location headers using the
request. While this matches Firefox, this does not match the spec or
Safari's behavior. Instead, the spec says to resolve the location header
based on the response's URL.

This comes up if the FetchEvent was for /, but the Service Worker
responded with ev.respondWith(fetch("/foo/", {redirect: "manual"})). In
that case, a Location: bar.html header would result in /bar.html by our
version and /foo/bar.html by the spec's version.

Align with the spec. This makes the redirect go where it would have gone
under {redirect: "follow"}. This has two platform-visible behavior
changes:

- First, cases like the above will result in a different URL.

- Second, script-constructed Response objects do not have a URL list. If
  the URLs are absolute, this works fine. If they are relative, those
  fetches will now result in a network error. Note Response.redirect()
  internally constructs absolute URLs, so those continue to work. This
  only affects ev.respondWith(new Response(... location: "bar.html"}})).

Both of these changes match Safari.

Note that, as of writing, the Fetch spec describes this behavior in
terms of a location URL property on the response object. This would
require computing the location URL earlier and preserving it across many
layers, including persisting in CacheStorage. See
https://chromium-review.googlesource.com/c/chromium/src/+/2648648.

Instead, this CL uses the equivalent formulation in
whatwg/fetch#1149. See also discussion in
whatwg/fetch#1146.

Bug: 1170379
Change-Id: Ibb6b12566244fd259029e67787dd7f08edeece9d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2665871
Reviewed-by: Makoto Shimazu <shimazuchromium.org>
Reviewed-by: Kinuko Yasuda <kinukochromium.org>
Reviewed-by: Ben Kelly <wanderviewchromium.org>
Commit-Queue: David Benjamin <davidbenchromium.org>
Cr-Commit-Position: refs/heads/master{#850874}

--

wpt-commits: 020c59f0ae3ce0a5649c8e811faca2101d947d63
wpt-pr: 27444

UltraBlame original commit: f5404d5590f52e0ccf7100a37b1429363ca23c0c
  • Loading branch information
marco-c committed Feb 10, 2021
1 parent e1c2e49 commit bf79b9d
Show file tree
Hide file tree
Showing 5 changed files with 1,668 additions and 0 deletions.
Loading

0 comments on commit bf79b9d

Please sign in to comment.