Changeset 228326 in webkit


Ignore:
Timestamp:
Feb 9, 2018 10:27:13 AM (6 years ago)
Author:
commit-queue@webkit.org
Message:

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:
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r228319 r228326  
     12018-02-09  Youenn Fablet  <youenn@apple.com>
     2
     3        Add support for cache storage of blob response
     4        https://bugs.webkit.org/show_bug.cgi?id=182637
     5
     6        Reviewed by Brady Eidson.
     7
     8        * web-platform-tests/service-workers/cache-storage/script-tests/cache-put.js:
     9        (cache_test.async):
     10        * web-platform-tests/service-workers/cache-storage/serviceworker/cache-put.https-expected.txt:
     11        * web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt:
     12        * web-platform-tests/service-workers/cache-storage/worker/cache-put.https-expected.txt:
     13        * web-platform-tests/service-workers/cache-storage/window/cache-put.https.html:
     14
    1152018-02-09  Javier Fernandez  <jfernandez@igalia.com>
    216
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/script-tests/cache-put.js

    r220223 r228326  
    336336  }, 'Cache.put should store Response.redirect() correctly');
    337337
     338cache_test(async (cache) => {
     339    var request = new Request(test_url);
     340    var response = new Response(new Blob([test_body]));
     341    await cache.put(request, response);
     342    var cachedResponse = await cache.match(request);
     343    assert_equals(await cachedResponse.text(), test_body);
     344  }, 'Cache.put called with simple Request and blob Response');
     345
    338346done();
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/serviceworker/cache-put.https-expected.txt

    r224250 r228326  
    2424PASS Cache.put with an embedded VARY:* Response
    2525PASS Cache.put should store Response.redirect() correctly
     26PASS Cache.put called with simple Request and blob Response
    2627
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt

    r221024 r228326  
    2323PASS Cache.put with an embedded VARY:* Response
    2424PASS Cache.put should store Response.redirect() correctly
     25PASS Cache.put called with simple Request and blob Response
     26FAIL Cache.put called with simple Request and form data Response promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
    2527
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-put.https.html

    r220223 r228326  
    77<script src="../resources/test-helpers.js"></script>
    88<script src="../script-tests/cache-put.js"></script>
     9<script>
     10cache_test(async (cache) => {
     11    var formData = new FormData();
     12    formData.append("name", "value");
     13
     14    var request = new Request(test_url);
     15    var response = new Response(formData);
     16    await cache.put(request, response);
     17    var cachedResponse = await cache.match(request);
     18    var cachedResponseText = await cachedResponse.text();
     19    assert_true(cachedResponseText.indexOf("name=\"name\"\r\n\r\nvalue") !== -1);
     20  }, 'Cache.put called with simple Request and form data Response');
     21</script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/worker/cache-put.https-expected.txt

    r221704 r228326  
    2323PASS Cache.put with an embedded VARY:* Response
    2424PASS Cache.put should store Response.redirect() correctly
     25PASS Cache.put called with simple Request and blob Response
    2526
  • trunk/Source/WebCore/ChangeLog

    r228325 r228326  
     12018-02-09  Youenn Fablet  <youenn@apple.com>
     2
     3        Add support for cache storage of blob response
     4        https://bugs.webkit.org/show_bug.cgi?id=182637
     5
     6        Reviewed by Brady Eidson.
     7
     8        Covered by updated WPT test.
     9        When putting a blob response in cache, create a readable stream to easily get the body.
     10        Make clear that caching form data is not supported.
     11
     12        * Modules/cache/DOMCache.cpp:
     13        (WebCore::DOMCache::put):
     14        * Modules/fetch/FetchBody.h:
     15        (WebCore::FetchBody::isBlob const):
     16        (WebCore::FetchBody::isFormData const):
     17        * Modules/fetch/FetchResponse.h:
     18
    1192018-02-09  Youenn Fablet  <youenn@apple.com>
    220
  • trunk/Source/WebCore/Modules/cache/DOMCache.cpp

    r228199 r228326  
    341341    }
    342342
     343    if (response->isBlobFormData()) {
     344        promise.reject(Exception { NotSupportedError, ASCIILiteral("Not implemented") });
     345        return;
     346    }
     347
     348    // FIXME: for efficiency, we should load blobs directly instead of going through the readableStream path.
     349    if (response->isBlobBody())
     350        response->readableStream(*scriptExecutionContext()->execState());
     351
    343352    if (response->isBodyReceivedByChunk()) {
    344353        response->consumeBodyReceivedByChunk([promise = WTFMove(promise), request = WTFMove(request), response = WTFMove(response), data = SharedBuffer::create(), pendingActivity = makePendingActivity(*this), this](auto&& result) mutable {
  • trunk/Source/WebCore/Modules/fetch/FetchBody.h

    r226906 r228326  
    8686    }
    8787
     88    bool isBlob() const { return WTF::holds_alternative<Ref<const Blob>>(m_data); }
     89    bool isFormData() const { return WTF::holds_alternative<Ref<FormData>>(m_data); }
     90
    8891private:
    8992    explicit FetchBody(Ref<const Blob>&& data) : m_data(WTFMove(data)) { }
     
    103106    void consumeBlob(FetchBodyOwner&, Ref<DeferredPromise>&&);
    104107
    105     bool isBlob() const { return WTF::holds_alternative<Ref<const Blob>>(m_data); }
    106     bool isFormData() const { return WTF::holds_alternative<Ref<FormData>>(m_data); }
    107108    bool isArrayBuffer() const { return WTF::holds_alternative<Ref<const ArrayBuffer>>(m_data); }
    108109    bool isArrayBufferView() const { return WTF::holds_alternative<Ref<const ArrayBufferView>>(m_data); }
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.h

    r228218 r228326  
    9494    bool isLoading() const { return !!m_bodyLoader; }
    9595    bool isBodyReceivedByChunk() const { return isLoading() || hasReadableStreamBody(); }
     96    bool isBlobBody() const { return !isBodyNull() && body().isBlob(); }
     97    bool isBlobFormData() const { return !isBodyNull() && body().isFormData(); }
    9698
    9799    using ConsumeDataByChunkCallback = WTF::Function<void(ExceptionOr<ReadableStreamChunk*>&&)>;
Note: See TracChangeset for help on using the changeset viewer.