Skip to content

Commit

Permalink
Fix XHR/Fetch API when hitting <link rel=preload as=fetch>
Browse files Browse the repository at this point in the history
Previously, when XHR/fetch API reuses a
<link rel=preload as=fetch> response with HTTP 4xx,
XHR onabort was fired and fetch API's text() was stalled
(never resolved nor rejected),
due to loading cancellation,
while XHR/fetch API should be successful because
HTTP 4xx isn't considered as a network error in the spec.

This CL fixes this by not considering HTTP 4xx as an error.

As a side effect, this CL fires load events instead of
error events for <link rel=preload as=fetch> + HTTP 4xx.
While the desired behavior about the events on
`<link rel=preload as=fetch>` are still under
discussion at whatwg/html#1142,
changing the event on Chromium is probably fine,
because Firefox/Safari fire different events
(load/error, respectively) for HTTP 4xx.

Original attempt:
https://chromium-review.googlesource.com/c/chromium/src/+/3540965

Bug: 1305317, 1318618
Change-Id: Ic8ec587599f4db28837ed3c1b19b2a5a58e1a4c4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3585999
Reviewed-by: Mason Freed <[email protected]>
Commit-Queue: Hiroshige Hayashizaki <[email protected]>
Cr-Commit-Position: refs/heads/main@{#996524}
NOKEYCHECK=True
GitOrigin-RevId: 2feeb37f75b06beea1bafa843a11f9199ffb3739
  • Loading branch information
hiroshige-g authored and copybara-github committed Apr 27, 2022
1 parent 0dcd0da commit 846433a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions blink/renderer/platform/loader/fetch/raw_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ class PLATFORM_EXPORT RawResource final : public Resource {
// Resource implementation
void DidAddClient(ResourceClient*) override;
void AppendData(const char*, size_t) override;
bool ShouldIgnoreHTTPStatusCodeErrors() const override {
return !IsLinkPreload();
}

bool ShouldIgnoreHTTPStatusCodeErrors() const override { return true; }

void WillNotFollowRedirect() override;
void ResponseReceived(const ResourceResponse&) override;
void ResponseBodyReceived(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
This is a testharness.js-based test.
Found 68 tests; 59 PASS, 9 FAIL, 0 TIMEOUT, 0 NOTRUN.
Found 68 tests; 63 PASS, 5 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS success (image): preload events
PASS success (image): main
PASS 404 (image): preload events
Expand Down Expand Up @@ -32,8 +32,8 @@ PASS CSP-error (script): preload events
PASS CSP-error (script): main
PASS success (xhr): preload events
PASS success (xhr): main
FAIL 404 (xhr): preload events assert_unreached: preload onerror Reached unreachable code
FAIL 404 (xhr): main assert_unreached: XHR onabort Reached unreachable code
PASS 404 (xhr): preload events
PASS 404 (xhr): main
PASS CORS (xhr): preload events
PASS CORS (xhr): main
PASS CORS-error (xhr): preload events
Expand All @@ -42,8 +42,8 @@ PASS CSP-error (xhr): preload events
PASS CSP-error (xhr): main
PASS success (fetch): preload events
PASS success (fetch): main
FAIL 404 (fetch): preload events assert_unreached: preload onerror Reached unreachable code
FAIL 404 (fetch): main assert_unreached: fetch() completed but text() timeout Reached unreachable code
PASS 404 (fetch): preload events
PASS 404 (fetch): main
PASS CORS (fetch): preload events
PASS CORS (fetch): main
PASS CORS-error (fetch): preload events
Expand Down

0 comments on commit 846433a

Please sign in to comment.