Title: [205253] trunk
Revision
205253
Author
[email protected]
Date
2016-08-31 09:44:49 -0700 (Wed, 31 Aug 2016)

Log Message

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

Patch by Youenn Fablet <[email protected]> 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.

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (205252 => 205253)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2016-08-31 16:44:27 UTC (rev 205252)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2016-08-31 16:44:49 UTC (rev 205253)
@@ -1,3 +1,13 @@
+2016-08-31  Youenn Fablet  <[email protected]>
+
+        [Fetch API] Request construction failure should not set "bodyUsed"
+        https://bugs.webkit.org/show_bug.cgi?id=161432
+
+        Reviewed by Alex Christensen.
+
+        * web-platform-tests/fetch/api/request/request-disturbed-expected.txt:
+        * web-platform-tests/fetch/api/request/request-disturbed.html:
+
 2016-08-31  Romain Bellessort  <[email protected]>
 
         [Streams API] Align getReader() with spec

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-disturbed-expected.txt (205252 => 205253)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-disturbed-expected.txt	2016-08-31 16:44:27 UTC (rev 205252)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-disturbed-expected.txt	2016-08-31 16:44:49 UTC (rev 205253)
@@ -4,4 +4,5 @@
 PASS Check creating a new request from a disturbed request 
 PASS Input request used for creating new request became disturbed 
 PASS Check consuming a disturbed request 
+PASS Request construction failure should not set "bodyUsed" 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-disturbed.html (205252 => 205253)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-disturbed.html	2016-08-31 16:44:27 UTC (rev 205252)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-disturbed.html	2016-08-31 16:44:49 UTC (rev 205253)
@@ -50,6 +50,30 @@
         assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is disturbed");
         return promise_rejects(test, new TypeError(), bodyConsumed.blob());
       }, "Check consuming a disturbed request");
+
+      test(function() {
+        var req = new Request(URL, {method: 'POST', body: 'hello'});
+        assert_false(req.bodyUsed,
+                     'Request should not be flagged as used if it has not been ' +
+                     'consumed.');
+        assert_throws(
+          {name: 'TypeError'},
+          function() { new Request(req, {method: 'GET'}); },
+          'A get request may not have body.');
+
+        assert_false(req.bodyUsed, 'After the GET case');
+
+        assert_throws(
+          {name: 'TypeError'},
+          function() { new Request(req, {method: 'CONNECT'}); },
+          'Request() with a forbidden method must throw.');
+
+        assert_false(req.bodyUsed, 'After the forbidden method case');
+
+        var req2 = new Request(req);
+        assert_true(req.bodyUsed,
+                    'Request should be flagged as used if it has been consumed.');
+      }, 'Request construction failure should not set "bodyUsed"');
     </script>
   </body>
 </html>

Modified: trunk/Source/WebCore/ChangeLog (205252 => 205253)


--- trunk/Source/WebCore/ChangeLog	2016-08-31 16:44:27 UTC (rev 205252)
+++ trunk/Source/WebCore/ChangeLog	2016-08-31 16:44:49 UTC (rev 205253)
@@ -1,5 +1,19 @@
 2016-08-31  Youenn Fablet  <[email protected]>
 
+        [Fetch API] Request construction failure should not set "bodyUsed"
+        https://bugs.webkit.org/show_bug.cgi?id=161432
+
+        Reviewed by Alex Christensen.
+
+        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.
+
+2016-08-31  Youenn Fablet  <[email protected]>
+
         [Fetch API] Response bodyUsed should check for its body disturbed state
         https://bugs.webkit.org/show_bug.cgi?id=161429
 

Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp (205252 => 205253)


--- trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp	2016-08-31 16:44:27 UTC (rev 205252)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp	2016-08-31 16:44:49 UTC (rev 205253)
@@ -193,10 +193,8 @@
     return true;
 }
 
-static bool validateBodyAndMethod(const FetchBody& body, const FetchRequest::InternalRequest& internalRequest)
+static bool methodCanHaveBody(const FetchRequest::InternalRequest& internalRequest)
 {
-    if (body.isEmpty())
-        return true;
     return internalRequest.request.httpMethod() != "GET" && internalRequest.request.httpMethod() != "HEAD";
 }
 
@@ -257,6 +255,11 @@
 void FetchRequest::setBody(JSC::ExecState& execState, JSC::JSValue body, FetchRequest* request, ExceptionCode& ec)
 {
     if (!body.isNull()) {
+        if (!methodCanHaveBody(m_internalRequest)) {
+            ec = TypeError;
+            return;
+        }
+
         ASSERT(scriptExecutionContext());
         m_body = FetchBody::extract(*scriptExecutionContext(), execState, body);
         if (m_body.type() == FetchBody::Type::None) {
@@ -265,14 +268,16 @@
         }
     }
     else if (request && !request->m_body.isEmpty()) {
+        if (!methodCanHaveBody(m_internalRequest)) {
+            ec = TypeError;
+            return;
+        }
+
         m_body = FetchBody::extractFromBody(&request->m_body);
         request->setDisturbed();
     }
 
     m_body.updateContentType(m_headers);
-
-    if (!validateBodyAndMethod(m_body, m_internalRequest))
-        ec = TypeError;
 }
 
 String FetchRequest::referrer() const
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to