Changeset 205253 in webkit


Ignore:
Timestamp:
Aug 31, 2016 9:44:49 AM (8 years ago)
Author:
commit-queue@webkit.org
Message:

[Fetch API] Request construction failure should not set "bodyUsed"
https://bugs.webkit.org/show_bug.cgi?id=161432

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

LayoutTests/imported/w3c:

  • web-platform-tests/fetch/api/request/request-disturbed-expected.txt:
  • web-platform-tests/fetch/api/request/request-disturbed.html:

Source/WebCore:

Covered by added sub-test coming from chromium fetch test suite.

  • Modules/fetch/FetchRequest.cpp:

(WebCore::methodCanHaveBody):
(WebCore::FetchRequest::setBody): Check whether request can have a body before disturbing the passed request.
(WebCore::validateBodyAndMethod): Deleted.

Location:
trunk
Files:
5 edited

Legend:

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

    r205248 r205253  
     12016-08-31  Youenn Fablet  <youenn@apple.com>
     2
     3        [Fetch API] Request construction failure should not set "bodyUsed"
     4        https://bugs.webkit.org/show_bug.cgi?id=161432
     5
     6        Reviewed by Alex Christensen.
     7
     8        * web-platform-tests/fetch/api/request/request-disturbed-expected.txt:
     9        * web-platform-tests/fetch/api/request/request-disturbed.html:
     10
    1112016-08-31  Romain Bellessort  <romain.bellessort@crf.canon.fr>
    212
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-disturbed-expected.txt

    r195954 r205253  
    55PASS Input request used for creating new request became disturbed
    66PASS Check consuming a disturbed request
     7PASS Request construction failure should not set "bodyUsed"
    78
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-disturbed.html

    r195954 r205253  
    5151        return promise_rejects(test, new TypeError(), bodyConsumed.blob());
    5252      }, "Check consuming a disturbed request");
     53
     54      test(function() {
     55        var req = new Request(URL, {method: 'POST', body: 'hello'});
     56        assert_false(req.bodyUsed,
     57                     'Request should not be flagged as used if it has not been ' +
     58                     'consumed.');
     59        assert_throws(
     60          {name: 'TypeError'},
     61          function() { new Request(req, {method: 'GET'}); },
     62          'A get request may not have body.');
     63
     64        assert_false(req.bodyUsed, 'After the GET case');
     65
     66        assert_throws(
     67          {name: 'TypeError'},
     68          function() { new Request(req, {method: 'CONNECT'}); },
     69          'Request() with a forbidden method must throw.');
     70
     71        assert_false(req.bodyUsed, 'After the forbidden method case');
     72
     73        var req2 = new Request(req);
     74        assert_true(req.bodyUsed,
     75                    'Request should be flagged as used if it has been consumed.');
     76      }, 'Request construction failure should not set "bodyUsed"');
    5377    </script>
    5478  </body>
  • trunk/Source/WebCore/ChangeLog

    r205251 r205253  
     12016-08-31  Youenn Fablet  <youenn@apple.com>
     2
     3        [Fetch API] Request construction failure should not set "bodyUsed"
     4        https://bugs.webkit.org/show_bug.cgi?id=161432
     5
     6        Reviewed by Alex Christensen.
     7
     8        Covered by added sub-test coming from chromium fetch test suite.
     9
     10        * Modules/fetch/FetchRequest.cpp:
     11        (WebCore::methodCanHaveBody):
     12        (WebCore::FetchRequest::setBody): Check whether request can have a body before disturbing the passed request.
     13        (WebCore::validateBodyAndMethod): Deleted.
     14
    1152016-08-31  Youenn Fablet  <youenn@apple.com>
    216
  • trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp

    r205251 r205253  
    194194}
    195195
    196 static bool validateBodyAndMethod(const FetchBody& body, const FetchRequest::InternalRequest& internalRequest)
    197 {
    198     if (body.isEmpty())
    199         return true;
     196static bool methodCanHaveBody(const FetchRequest::InternalRequest& internalRequest)
     197{
    200198    return internalRequest.request.httpMethod() != "GET" && internalRequest.request.httpMethod() != "HEAD";
    201199}
     
    258256{
    259257    if (!body.isNull()) {
     258        if (!methodCanHaveBody(m_internalRequest)) {
     259            ec = TypeError;
     260            return;
     261        }
     262
    260263        ASSERT(scriptExecutionContext());
    261264        m_body = FetchBody::extract(*scriptExecutionContext(), execState, body);
     
    266269    }
    267270    else if (request && !request->m_body.isEmpty()) {
     271        if (!methodCanHaveBody(m_internalRequest)) {
     272            ec = TypeError;
     273            return;
     274        }
     275
    268276        m_body = FetchBody::extractFromBody(&request->m_body);
    269277        request->setDisturbed();
     
    271279
    272280    m_body.updateContentType(m_headers);
    273 
    274     if (!validateBodyAndMethod(m_body, m_internalRequest))
    275         ec = TypeError;
    276281}
    277282
Note: See TracChangeset for help on using the changeset viewer.