Skip to content
Permalink
Browse files
Add support for cache storage of blob response
https://bugs.webkit.org/show_bug.cgi?id=182637

Patch by Youenn Fablet <youenn@apple.com> on 2018-02-09
Reviewed by Brady Eidson.

LayoutTests/imported/w3c:

* web-platform-tests/service-workers/cache-storage/script-tests/cache-put.js:
(cache_test.async):
* web-platform-tests/service-workers/cache-storage/serviceworker/cache-put.https-expected.txt:
* web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt:
* web-platform-tests/service-workers/cache-storage/worker/cache-put.https-expected.txt:
* web-platform-tests/service-workers/cache-storage/window/cache-put.https.html:

Source/WebCore:

Covered by updated WPT test.
When putting a blob response in cache, create a readable stream to easily get the body.
Make clear that caching form data is not supported.

* Modules/cache/DOMCache.cpp:
(WebCore::DOMCache::put):
* Modules/fetch/FetchBody.h:
(WebCore::FetchBody::isBlob const):
(WebCore::FetchBody::isFormData const):
* Modules/fetch/FetchResponse.h:

Canonical link: https://commits.webkit.org/198457@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@228326 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
youennf authored and webkit-commit-queue committed Feb 9, 2018
1 parent e06af57 commit df6a492dc742ea35a771f07a4309fc27718d8c8f
@@ -1,3 +1,17 @@
2018-02-09 Youenn Fablet <youenn@apple.com>

Add support for cache storage of blob response
https://bugs.webkit.org/show_bug.cgi?id=182637

Reviewed by Brady Eidson.

* web-platform-tests/service-workers/cache-storage/script-tests/cache-put.js:
(cache_test.async):
* web-platform-tests/service-workers/cache-storage/serviceworker/cache-put.https-expected.txt:
* web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt:
* web-platform-tests/service-workers/cache-storage/worker/cache-put.https-expected.txt:
* web-platform-tests/service-workers/cache-storage/window/cache-put.https.html:

2018-02-09 Javier Fernandez <jfernandez@igalia.com>

[css-align] Implement the new behavior of 'legacy' for justify-items
@@ -335,4 +335,12 @@ cache_test(function(cache) {
});
}, 'Cache.put should store Response.redirect() correctly');

cache_test(async (cache) => {
var request = new Request(test_url);
var response = new Response(new Blob([test_body]));
await cache.put(request, response);
var cachedResponse = await cache.match(request);
assert_equals(await cachedResponse.text(), test_body);
}, 'Cache.put called with simple Request and blob Response');

done();
@@ -23,4 +23,5 @@ PASS getReader() after Cache.put
PASS Cache.put with a VARY:* Response
PASS Cache.put with an embedded VARY:* Response
PASS Cache.put should store Response.redirect() correctly
PASS Cache.put called with simple Request and blob Response

@@ -22,4 +22,6 @@ PASS getReader() after Cache.put
PASS Cache.put with a VARY:* Response
PASS Cache.put with an embedded VARY:* Response
PASS Cache.put should store Response.redirect() correctly
PASS Cache.put called with simple Request and blob Response
FAIL Cache.put called with simple Request and form data Response promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"

@@ -6,3 +6,16 @@
<script src="/resources/testharnessreport.js"></script>
<script src="../resources/test-helpers.js"></script>
<script src="../script-tests/cache-put.js"></script>
<script>
cache_test(async (cache) => {
var formData = new FormData();
formData.append("name", "value");

var request = new Request(test_url);
var response = new Response(formData);
await cache.put(request, response);
var cachedResponse = await cache.match(request);
var cachedResponseText = await cachedResponse.text();
assert_true(cachedResponseText.indexOf("name=\"name\"\r\n\r\nvalue") !== -1);
}, 'Cache.put called with simple Request and form data Response');
</script>
@@ -22,4 +22,5 @@ PASS getReader() after Cache.put
PASS Cache.put with a VARY:* Response
PASS Cache.put with an embedded VARY:* Response
PASS Cache.put should store Response.redirect() correctly
PASS Cache.put called with simple Request and blob Response

@@ -1,3 +1,21 @@
2018-02-09 Youenn Fablet <youenn@apple.com>

Add support for cache storage of blob response
https://bugs.webkit.org/show_bug.cgi?id=182637

Reviewed by Brady Eidson.

Covered by updated WPT test.
When putting a blob response in cache, create a readable stream to easily get the body.
Make clear that caching form data is not supported.

* Modules/cache/DOMCache.cpp:
(WebCore::DOMCache::put):
* Modules/fetch/FetchBody.h:
(WebCore::FetchBody::isBlob const):
(WebCore::FetchBody::isFormData const):
* Modules/fetch/FetchResponse.h:

2018-02-09 Youenn Fablet <youenn@apple.com>

Make CoreAudioCaptureSource error logging be release logging
@@ -340,6 +340,15 @@ void DOMCache::put(RequestInfo&& info, Ref<FetchResponse>&& response, DOMPromise
return;
}

if (response->isBlobFormData()) {
promise.reject(Exception { NotSupportedError, ASCIILiteral("Not implemented") });
return;
}

// FIXME: for efficiency, we should load blobs directly instead of going through the readableStream path.
if (response->isBlobBody())
response->readableStream(*scriptExecutionContext()->execState());

if (response->isBodyReceivedByChunk()) {
response->consumeBodyReceivedByChunk([promise = WTFMove(promise), request = WTFMove(request), response = WTFMove(response), data = SharedBuffer::create(), pendingActivity = makePendingActivity(*this), this](auto&& result) mutable {

@@ -85,6 +85,9 @@ class FetchBody {
m_readableStream = WTFMove(stream);
}

bool isBlob() const { return WTF::holds_alternative<Ref<const Blob>>(m_data); }
bool isFormData() const { return WTF::holds_alternative<Ref<FormData>>(m_data); }

private:
explicit FetchBody(Ref<const Blob>&& data) : m_data(WTFMove(data)) { }
explicit FetchBody(Ref<const ArrayBuffer>&& data) : m_data(WTFMove(data)) { }
@@ -102,8 +105,6 @@ class FetchBody {
void consumeText(Ref<DeferredPromise>&&, const String&);
void consumeBlob(FetchBodyOwner&, Ref<DeferredPromise>&&);

bool isBlob() const { return WTF::holds_alternative<Ref<const Blob>>(m_data); }
bool isFormData() const { return WTF::holds_alternative<Ref<FormData>>(m_data); }
bool isArrayBuffer() const { return WTF::holds_alternative<Ref<const ArrayBuffer>>(m_data); }
bool isArrayBufferView() const { return WTF::holds_alternative<Ref<const ArrayBufferView>>(m_data); }
bool isURLSearchParams() const { return WTF::holds_alternative<Ref<const URLSearchParams>>(m_data); }
@@ -93,6 +93,8 @@ class FetchResponse final : public FetchBodyOwner {

bool isLoading() const { return !!m_bodyLoader; }
bool isBodyReceivedByChunk() const { return isLoading() || hasReadableStreamBody(); }
bool isBlobBody() const { return !isBodyNull() && body().isBlob(); }
bool isBlobFormData() const { return !isBodyNull() && body().isFormData(); }

using ConsumeDataByChunkCallback = WTF::Function<void(ExceptionOr<ReadableStreamChunk*>&&)>;
void consumeBodyReceivedByChunk(ConsumeDataByChunkCallback&&);

0 comments on commit df6a492

Please sign in to comment.