[Fetch API] Implement abortable fetch
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Jan 2019 00:01:43 +0000 (00:01 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Jan 2019 00:01:43 +0000 (00:01 +0000)
commit45bd5cc26c725f2031a913addd114b8df7c93ef5
treec2aabecdd7d71f2598db074da5e2ec747bf976b3
parentc678edff4195700fad7e36447177705df6c38f93
[Fetch API] Implement abortable fetch
https://bugs.webkit.org/show_bug.cgi?id=174980
<rdar://problem/46861402>

Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

Fixed tests to run in WebKit CI.
Also fixed a bug in a test where the fetch response body is not actually empty.

* web-platform-tests/fetch/api/abort/cache.https-expected.txt:
* web-platform-tests/fetch/api/abort/general-serviceworker.https-expected.txt:
* web-platform-tests/fetch/api/abort/general.any-expected.txt:
* web-platform-tests/fetch/api/abort/general.any.js:
* web-platform-tests/fetch/api/abort/general.any.worker-expected.txt:
* web-platform-tests/fetch/api/abort/serviceworker-intercepted.https-expected.txt:
* web-platform-tests/fetch/api/response/response-consume-stream-expected.txt:

Source/WebCore:

Add an AbortSignal to FetchRequest.

Add support for AbortSignal algorithm.
The fetch request signal is added an algorithm to abort the fetch.
Update clone algorithm to let signal of the cloned request be following the origin request.

Update ReadableStream error handling to return an exception instead of a string.
This allows passing an AbortError instead of a TypeError as previously done.

Update FetchBodyOwner to store a loading error either as an exception or as a resource error.
The latter is used for passing the error from service worker back to the page.
The former is used to pass it to ReadableStream or body accessors.

Covered by enabled tests.

* Modules/cache/DOMCache.cpp:
(WebCore::DOMCache::put):
* Modules/fetch/FetchBody.cpp:
(WebCore::FetchBody::consumeAsStream):
(WebCore::FetchBody::loadingFailed):
* Modules/fetch/FetchBody.h:
* Modules/fetch/FetchBodyConsumer.cpp:
(WebCore::FetchBodyConsumer::loadingFailed):
* Modules/fetch/FetchBodyConsumer.h:
* Modules/fetch/FetchBodyOwner.cpp:
(WebCore::FetchBodyOwner::arrayBuffer):
(WebCore::FetchBodyOwner::blob):
(WebCore::FetchBodyOwner::cloneBody):
(WebCore::FetchBodyOwner::formData):
(WebCore::FetchBodyOwner::json):
(WebCore::FetchBodyOwner::text):
(WebCore::FetchBodyOwner::loadBlob):
(WebCore::FetchBodyOwner::blobLoadingFailed):
(WebCore::FetchBodyOwner::consumeBodyAsStream):
(WebCore::FetchBodyOwner::setLoadingError):
* Modules/fetch/FetchBodyOwner.h:
(WebCore::FetchBodyOwner::loadingError const):
(WebCore::FetchBodyOwner::loadingException const):
* Modules/fetch/FetchBodySource.cpp:
(WebCore::FetchBodySource::error):
* Modules/fetch/FetchBodySource.h:
* Modules/fetch/FetchRequest.cpp:
(WebCore::FetchRequest::initializeWith):
(WebCore::FetchRequest::clone):
* Modules/fetch/FetchRequest.h:
(WebCore::FetchRequest::FetchRequest):
* Modules/fetch/FetchRequest.idl:
* Modules/fetch/FetchRequestInit.h:
(WebCore::FetchRequestInit::hasMembers const):
* Modules/fetch/FetchRequestInit.idl:
* Modules/fetch/FetchResponse.cpp:
(WebCore::FetchResponse::clone):
(WebCore::FetchResponse::fetch):
(WebCore::FetchResponse::BodyLoader::didFail):
* Modules/fetch/FetchResponse.h:
* bindings/js/ReadableStreamDefaultController.h:
(WebCore::ReadableStreamDefaultController::error):
* dom/AbortSignal.cpp:
(WebCore::AbortSignal::abort):
(WebCore::AbortSignal::follow):
* dom/AbortSignal.h:

LayoutTests:

* TestExpectations: Enable abort tests.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239644 268f45cc-cd09-0410-ab3c-d52691b4dbfc
32 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/fetch/api/abort/cache.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/abort/general-serviceworker.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/abort/general.any-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/abort/general.any.js
LayoutTests/imported/w3c/web-platform-tests/fetch/api/abort/general.any.worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/abort/serviceworker-intercepted.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-stream-expected.txt
LayoutTests/platform/ios-simulator/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/Modules/cache/DOMCache.cpp
Source/WebCore/Modules/fetch/FetchBody.cpp
Source/WebCore/Modules/fetch/FetchBody.h
Source/WebCore/Modules/fetch/FetchBodyConsumer.cpp
Source/WebCore/Modules/fetch/FetchBodyConsumer.h
Source/WebCore/Modules/fetch/FetchBodyOwner.cpp
Source/WebCore/Modules/fetch/FetchBodyOwner.h
Source/WebCore/Modules/fetch/FetchBodySource.cpp
Source/WebCore/Modules/fetch/FetchBodySource.h
Source/WebCore/Modules/fetch/FetchRequest.cpp
Source/WebCore/Modules/fetch/FetchRequest.h
Source/WebCore/Modules/fetch/FetchRequest.idl
Source/WebCore/Modules/fetch/FetchRequestInit.h
Source/WebCore/Modules/fetch/FetchRequestInit.idl
Source/WebCore/Modules/fetch/FetchResponse.cpp
Source/WebCore/Modules/fetch/FetchResponse.h
Source/WebCore/bindings/js/ReadableStreamDefaultController.h
Source/WebCore/dom/AbortSignal.cpp
Source/WebCore/dom/AbortSignal.h
Source/WebCore/workers/service/context/ServiceWorkerFetch.cpp