Changeset 204225 in webkit


Ignore:
Timestamp:
Aug 6, 2016 1:51:01 AM (8 years ago)
Author:
commit-queue@webkit.org
Message:

[Fetch API] Fetching with a FormData body should reject until it is implemented
https://bugs.webkit.org/show_bug.cgi?id=160595

Patch by Youenn Fablet <youenn@apple.com> on 2016-08-06
Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

Adding new tests to cover changes.
Removing HEAD with body test as it throws as expected and is redundant with
web-platform-tests/fetch/api/request/request-init-002.html.

  • web-platform-tests/fetch/api/basic/request-headers-expected.txt:
  • web-platform-tests/fetch/api/basic/request-headers-worker-expected.txt:
  • web-platform-tests/fetch/api/basic/request-headers.js:

(checkContentType):
(requestHeaders):

Source/WebCore:

Covered by updated tests.

This patch ensures that fetch will throw if trying to upload something that is not supported.
This is the case of BufferSource (FetchBody does not yet extract it) and FormData (no upload support yet).

  • Modules/fetch/FetchBody.cpp:

(WebCore::FetchBody::extract): Added a FIXME.

  • Modules/fetch/FetchBodyOwner.h:

(WebCore::FetchBodyOwner::bodyType): Getter used by FetchResponse.

  • Modules/fetch/FetchRequest.cpp:

(WebCore::FetchRequest::setBody): Throwing if given body parameter cannot be extracted by FetchBody.
This ensures that a fetch with a body that cannot be uploaded will fail.
This is the case of BufferSource which is not yet supported.

  • Modules/fetch/FetchResponse.cpp:

(WebCore::FetchResponse::fetch): Rejecting fetch promise if trying to upload a FormData as it is not implemented.

Location:
trunk
Files:
9 edited

Legend:

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

    r204224 r204225  
     12016-08-06  Youenn Fablet  <youenn@apple.com>
     2
     3        [Fetch API] Fetching with a FormData body should reject until it is implemented
     4        https://bugs.webkit.org/show_bug.cgi?id=160595
     5
     6        Reviewed by Alex Christensen.
     7
     8        Adding new tests to cover changes.
     9        Removing HEAD with body test as it throws as expected and is redundant with
     10        web-platform-tests/fetch/api/request/request-init-002.html.
     11
     12        * web-platform-tests/fetch/api/basic/request-headers-expected.txt:
     13        * web-platform-tests/fetch/api/basic/request-headers-worker-expected.txt:
     14        * web-platform-tests/fetch/api/basic/request-headers.js:
     15        (checkContentType):
     16        (requestHeaders):
     17
    1182016-08-06  Youenn Fablet  <youenn@apple.com>
    219
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers-expected.txt

    r204079 r204225  
    11
    2 FAIL Fetch with GET assert_equals: Request has header origin: http://localhost:8800 expected (string) "http://localhost:8800" but got (object) null
    3 FAIL Fetch with HEAD assert_equals: Request has header origin: http://localhost:8800 expected (string) "http://localhost:8800" but got (object) null
    4 FAIL Fetch with HEAD with body promise_test: Unhandled rejection with value: object "TypeError: Type error"
     2FAIL Fetch with GET assert_equals: Request should have header origin: http://localhost:8800 expected (string) "http://localhost:8800" but got (object) null
     3FAIL Fetch with HEAD assert_equals: Request should have header content-length: null expected (object) null but got (string) "0"
    54PASS Fetch with PUT without body
    65PASS Fetch with PUT with body
    76PASS Fetch with POST without body
    8 PASS Fetch with POST with body
    9 FAIL Fetch with Chicken assert_equals: Request has header content-length: null expected (object) null but got (string) "0"
     7PASS Fetch with POST with text body
     8FAIL Fetch with POST with FormData body promise_test: Unhandled rejection with value: object "TypeError: Uploading FormData is not yet implemented"
     9FAIL Fetch with POST with Blob body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
     10FAIL Fetch with POST with ArrayBuffer body promise_test: Unhandled rejection with value: object "TypeError: Type error"
     11PASS Fetch with POST with Blob body with mime type
     12FAIL Fetch with Chicken assert_equals: Request should have header content-length: null expected (object) null but got (string) "0"
    1013PASS Fetch with Chicken with body
    1114
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers-worker-expected.txt

    r204079 r204225  
    11
    2 FAIL Fetch with GET assert_equals: Request has header origin: http://localhost:8800 expected (string) "http://localhost:8800" but got (object) null
    3 FAIL Fetch with HEAD assert_equals: Request has header origin: http://localhost:8800 expected (string) "http://localhost:8800" but got (object) null
    4 FAIL Fetch with HEAD with body promise_test: Unhandled rejection with value: object "TypeError: Type error"
     2FAIL Fetch with GET assert_equals: Request should have header origin: http://localhost:8800 expected (string) "http://localhost:8800" but got (object) null
     3FAIL Fetch with HEAD assert_equals: Request should have header content-length: null expected (object) null but got (string) "0"
    54PASS Fetch with PUT without body
    65PASS Fetch with PUT with body
    76PASS Fetch with POST without body
    8 PASS Fetch with POST with body
    9 FAIL Fetch with Chicken assert_equals: Request has header content-length: null expected (object) null but got (string) "0"
     7PASS Fetch with POST with text body
     8FAIL Fetch with POST with Blob body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
     9FAIL Fetch with POST with ArrayBuffer body promise_test: Unhandled rejection with value: object "TypeError: Type error"
     10PASS Fetch with POST with Blob body with mime type
     11FAIL Fetch with Chicken assert_equals: Request should have header content-length: null expected (object) null but got (string) "0"
    1012PASS Fetch with Chicken with body
    1113
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.js

    r204079 r204225  
    44}
    55
     6function checkContentType(contentType, body)
     7{
     8    if (self.FormData && body instanceof self.FormData) {
     9        assert_true(contentType.startsWith("multipart/form-data;boundary="), "Request should have header content-type starting with multipart/form-data;boundary=, but got " + contentType);
     10        return;
     11    }
     12
     13    var expectedContentType = "text/plain;charset=UTF-8";
     14    if(body === null || body instanceof ArrayBuffer)
     15        expectedContentType = null;
     16    else if (body instanceof Blob)
     17        expectedContentType = body.type ? body.type : null;
     18
     19    assert_equals(contentType , expectedContentType, "Request should have header content-type: " + expectedContentType);
     20}
     21
    622function requestHeaders(desc, url, method, body, expectedOrigin, expectedContentLength) {
    7   var urlParameters = "?headers=origin|user-agent|accept-charset|content-length";
     23  var urlParameters = "?headers=origin|user-agent|accept-charset|content-length|content-type";
    824  var requestInit = {"method": method}
    925  if (body)
     
    1329      assert_equals(resp.status, 200, "HTTP status is 200");
    1430      assert_equals(resp.type , "basic", "Response's type is basic");
    15       assert_equals(resp.headers.get("x-request-origin") , expectedOrigin, "Request has header origin: " + expectedOrigin);
    16       assert_equals(resp.headers.get("x-request-content-length") , expectedContentLength, "Request has header content-length: " + expectedContentLength);
     31      checkContentType(resp.headers.get("x-request-content-type"), body);
     32      if (expectedContentLength !== undefined)
     33        assert_equals(resp.headers.get("x-request-content-length") , expectedContentLength, "Request should have header content-length: " + expectedContentLength);
    1734      assert_true(resp.headers.has("x-request-user-agent"), "Request has header user-agent");
    1835      assert_false(resp.headers.has("accept-charset"), "Request has header accept-charset");
     36      assert_equals(resp.headers.get("x-request-origin") , expectedOrigin, "Request should have header origin: " + expectedOrigin);
    1937    });
    2038  }, desc);
     
    2543requestHeaders("Fetch with GET", url, "GET", null, location.origin, null);
    2644requestHeaders("Fetch with HEAD", url, "HEAD", null, location.origin, null);
    27 requestHeaders("Fetch with HEAD with body", url, "HEAD", "Request's body", location.origin, "14");
    2845requestHeaders("Fetch with PUT without body", url, "POST", null, location.origin, "0");
    2946requestHeaders("Fetch with PUT with body", url, "PUT", "Request's body", location.origin, "14");
    3047requestHeaders("Fetch with POST without body", url, "POST", null, location.origin, "0");
    31 requestHeaders("Fetch with POST with body", url, "POST", "Request's body", location.origin, "14");
     48requestHeaders("Fetch with POST with text body", url, "POST", "Request's body", location.origin, "14");
     49if (self.FormData)
     50    requestHeaders("Fetch with POST with FormData body", url, "POST", new FormData(), location.origin);
     51requestHeaders("Fetch with POST with Blob body", url, "POST", new Blob(["Test"]), location.origin, "4");
     52requestHeaders("Fetch with POST with ArrayBuffer body", url, "POST", new ArrayBuffer(4), location.origin, "4");
     53requestHeaders("Fetch with POST with Blob body with mime type", url, "POST", new Blob(["Test"], { type: "text/maybe" }), location.origin, "4");
    3254requestHeaders("Fetch with Chicken", url, "Chicken", null, location.origin, null);
    3355requestHeaders("Fetch with Chicken with body", url, "Chicken", "Request's body", location.origin, "14");
  • trunk/Source/WebCore/ChangeLog

    r204224 r204225  
     12016-08-06  Youenn Fablet  <youenn@apple.com>
     2
     3        [Fetch API] Fetching with a FormData body should reject until it is implemented
     4        https://bugs.webkit.org/show_bug.cgi?id=160595
     5
     6        Reviewed by Alex Christensen.
     7
     8        Covered by updated tests.
     9
     10        This patch ensures that fetch will throw if trying to upload something that is not supported.
     11        This is the case of BufferSource (FetchBody does not yet extract it) and FormData (no upload support yet).
     12
     13        * Modules/fetch/FetchBody.cpp:
     14        (WebCore::FetchBody::extract): Added a FIXME.
     15        * Modules/fetch/FetchBodyOwner.h:
     16        (WebCore::FetchBodyOwner::bodyType): Getter used by FetchResponse.
     17        * Modules/fetch/FetchRequest.cpp:
     18        (WebCore::FetchRequest::setBody): Throwing if given body parameter cannot be extracted by FetchBody.
     19        This ensures that a fetch with a body that cannot be uploaded will fail.
     20        This is the case of BufferSource which is not yet supported.
     21        * Modules/fetch/FetchResponse.cpp:
     22        (WebCore::FetchResponse::fetch): Rejecting fetch promise if trying to upload a FormData as it is not implemented.
     23
    1242016-08-06  Youenn Fablet  <youenn@apple.com>
    225
  • trunk/Source/WebCore/Modules/fetch/FetchBody.cpp

    r203767 r204225  
    7777    if (value.inherits(JSReadableStream::info()))
    7878        return { Type::ReadableStream };
     79    // FIXME: Implement BufferSource extraction.
    7980    return { };
    8081}
  • trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h

    r203767 r204225  
    5757    bool isActive() const { return !!m_blobLoader; }
    5858
     59    FetchBody::Type bodyType() const { return m_body.type(); }
     60
    5961protected:
    6062    const FetchBody& body() const { return m_body; }
  • trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp

    r204224 r204225  
    257257void FetchRequest::setBody(JSC::ExecState& execState, JSC::JSValue body, FetchRequest* request, ExceptionCode& ec)
    258258{
    259     if (!body.isNull())
     259    if (!body.isNull()) {
    260260        m_body = FetchBody::extract(execState, body);
     261        if (m_body.type() == FetchBody::Type::None) {
     262            ec = TypeError;
     263            return;
     264        }
     265    }
    261266    else if (request && !request->m_body.isEmpty()) {
    262267        m_body = FetchBody::extractFromBody(&request->m_body);
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp

    r204020 r204225  
    106106    auto response = adoptRef(*new FetchResponse(context, FetchBody::loadingBody(), FetchHeaders::create(FetchHeaders::Guard::Immutable), { }));
    107107
     108    // FIXME: Implement form data upload.
     109    if (request.bodyType() == FetchBody::Type::FormData) {
     110        promise.reject(TypeError, "Uploading FormData is not yet implemented");
     111        return;
     112    }
    108113    // Setting pending activity until BodyLoader didFail or didSucceed callback is called.
    109114    response->setPendingActivity(response.ptr());
Note: See TracChangeset for help on using the changeset viewer.