<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[206632] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/206632">206632</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-09-30 01:04:52 -0700 (Fri, 30 Sep 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>[Fetch API] Add support for URLSearchParams body
https://bugs.webkit.org/show_bug.cgi?id=162667
Patch by Youenn Fablet <youennf@gmail.com> on 2016-09-30
Reviewed by Alex Christensen.
LayoutTests/imported/w3c:
Adding new tests to consume, stream and upload URLSearchParams bodies.
* 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):
* web-platform-tests/fetch/api/basic/request-upload-expected.txt: Added.
* web-platform-tests/fetch/api/basic/request-upload-worker-expected.txt: Added.
* web-platform-tests/fetch/api/basic/request-upload-worker.html: Added.
* web-platform-tests/fetch/api/basic/request-upload.html: Added.
* web-platform-tests/fetch/api/basic/request-upload.js: Added.
(testUpload):
* web-platform-tests/fetch/api/request/request-consume-empty-expected.txt:
* web-platform-tests/fetch/api/request/request-consume-empty.html:
* web-platform-tests/fetch/api/request/request-init-002-expected.txt:
* web-platform-tests/fetch/api/resources/echo-content.py: Added.
(main):
* web-platform-tests/fetch/api/response/response-consume-empty-expected.txt:
* web-platform-tests/fetch/api/response/response-consume-empty.html:
* web-platform-tests/fetch/api/response/response-consume-expected.txt:
* web-platform-tests/fetch/api/response/response-consume-stream-expected.txt:
* web-platform-tests/fetch/api/response/response-consume-stream.html:
* web-platform-tests/fetch/api/response/response-consume.html:
* web-platform-tests/fetch/api/response/response-init-002-expected.txt:
Source/WebCore:
Tests: imported/w3c/web-platform-tests/fetch/api/basic/request-upload-worker.html
imported/w3c/web-platform-tests/fetch/api/basic/request-upload.html
* Modules/fetch/FetchBody.cpp:
(WebCore::extractBytesFromText): Moving to a static function that should be moved to a String method.
(WebCore::FetchBody::FetchBody): Adding constructor for URLSearchParams.
(WebCore::FetchBody::extract): Adding URLSearchParams body initialization.
(WebCore::FetchBody::consume): Consuming URLSearchParams bodies.
(WebCore::FetchBody::consumeAsStream): Ditto.
(WebCore::FetchBody::consumeText): Updated to take a parameter to handle both text and URLSearchParams bodies.
(WebCore::FetchBody::bodyForInternalRequest): Add URLSearchParams body upload.
(WebCore::FetchBody::clone): Add URLSearchParams body cloning
* Modules/fetch/FetchBody.h:
(WebCore::FetchBody::urlSearchParamsBody):
* html/URLSearchParams.cpp:
(WebCore::URLSearchParams::toString):
* html/URLSearchParams.h:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsimportedw3cChangeLog">trunk/LayoutTests/imported/w3c/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapibasicrequestheadersexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapibasicrequestheadersworkerexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers-worker-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapibasicrequestheadersjs">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.js</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapirequestrequestconsumeemptyexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume-empty-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapirequestrequestconsumeemptyhtml">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume-empty.html</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapirequestrequestinit002expectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-002-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapiresponseresponseconsumeemptyexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-empty-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapiresponseresponseconsumeemptyhtml">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-empty.html</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapiresponseresponseconsumeexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapiresponseresponseconsumestreamexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-stream-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapiresponseresponseconsumestreamhtml">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-stream.html</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapiresponseresponseconsumehtml">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume.html</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapiresponseresponseinit002expectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-init-002-expected.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesfetchFetchBodycpp">trunk/Source/WebCore/Modules/fetch/FetchBody.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesfetchFetchBodyh">trunk/Source/WebCore/Modules/fetch/FetchBody.h</a></li>
<li><a href="#trunkSourceWebCorehtmlURLSearchParamscpp">trunk/Source/WebCore/html/URLSearchParams.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlURLSearchParamsh">trunk/Source/WebCore/html/URLSearchParams.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapibasicrequestuploadexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapibasicrequestuploadworkerexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload-worker-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapibasicrequestuploadworkerhtml">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload-worker.html</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapibasicrequestuploadhtml">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload.html</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapibasicrequestuploadjs">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload.js</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapiresourcesechocontentpy">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/echo-content.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsimportedw3cChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/ChangeLog (206631 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/ChangeLog        2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/ChangeLog        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -1,3 +1,36 @@
</span><ins>+2016-09-30 Youenn Fablet <youennf@gmail.com>
+
+ [Fetch API] Add support for URLSearchParams body
+ https://bugs.webkit.org/show_bug.cgi?id=162667
+
+ Reviewed by Alex Christensen.
+
+ Adding new tests to consume, stream and upload URLSearchParams bodies.
+
+ * 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):
+ * web-platform-tests/fetch/api/basic/request-upload-expected.txt: Added.
+ * web-platform-tests/fetch/api/basic/request-upload-worker-expected.txt: Added.
+ * web-platform-tests/fetch/api/basic/request-upload-worker.html: Added.
+ * web-platform-tests/fetch/api/basic/request-upload.html: Added.
+ * web-platform-tests/fetch/api/basic/request-upload.js: Added.
+ (testUpload):
+ * web-platform-tests/fetch/api/request/request-consume-empty-expected.txt:
+ * web-platform-tests/fetch/api/request/request-consume-empty.html:
+ * web-platform-tests/fetch/api/request/request-init-002-expected.txt:
+ * web-platform-tests/fetch/api/resources/echo-content.py: Added.
+ (main):
+ * web-platform-tests/fetch/api/response/response-consume-empty-expected.txt:
+ * web-platform-tests/fetch/api/response/response-consume-empty.html:
+ * web-platform-tests/fetch/api/response/response-consume-expected.txt:
+ * web-platform-tests/fetch/api/response/response-consume-stream-expected.txt:
+ * web-platform-tests/fetch/api/response/response-consume-stream.html:
+ * web-platform-tests/fetch/api/response/response-consume.html:
+ * web-platform-tests/fetch/api/response/response-init-002-expected.txt:
+
</ins><span class="cx"> 2016-09-29 Chris Dumez <cdumez@apple.com>
</span><span class="cx">
</span><span class="cx"> Add support for download attribute on area elements
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapibasicrequestheadersexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers-expected.txt (206631 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers-expected.txt        2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers-expected.txt        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -6,6 +6,7 @@
</span><span class="cx"> PASS Fetch with POST without body
</span><span class="cx"> PASS Fetch with POST with text body
</span><span class="cx"> PASS Fetch with POST with FormData body
</span><ins>+PASS Fetch with POST with URLSearchParams body
</ins><span class="cx"> FAIL 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"
</span><span class="cx"> FAIL Fetch with POST with ArrayBuffer body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
</span><span class="cx"> FAIL Fetch with POST with Uint8Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapibasicrequestheadersworkerexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers-worker-expected.txt (206631 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers-worker-expected.txt        2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers-worker-expected.txt        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -6,6 +6,7 @@
</span><span class="cx"> PASS Fetch with POST without body
</span><span class="cx"> PASS Fetch with POST with text body
</span><span class="cx"> FAIL Fetch with POST with FormData body Can't find variable: FormData
</span><ins>+PASS Fetch with POST with URLSearchParams body
</ins><span class="cx"> FAIL 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"
</span><span class="cx"> FAIL Fetch with POST with ArrayBuffer body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
</span><span class="cx"> FAIL Fetch with POST with Uint8Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapibasicrequestheadersjs"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.js (206631 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.js        2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.js        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -15,6 +15,8 @@
</span><span class="cx"> expectedContentType = null;
</span><span class="cx"> else if (body instanceof Blob)
</span><span class="cx"> expectedContentType = body.type ? body.type : null;
</span><ins>+ else if (body instanceof URLSearchParams)
+ expectedContentType = "application/x-www-form-urlencoded;charset=UTF-8";
</ins><span class="cx">
</span><span class="cx"> assert_equals(contentType , expectedContentType, "Request should have header content-type: " + expectedContentType);
</span><span class="cx"> }
</span><span class="lines">@@ -49,6 +51,7 @@
</span><span class="cx"> requestHeaders("Fetch with POST without body", url, "POST", null, location.origin, "0");
</span><span class="cx"> requestHeaders("Fetch with POST with text body", url, "POST", "Request's body", location.origin, "14");
</span><span class="cx"> requestHeaders("Fetch with POST with FormData body", url, "POST", function() { return new FormData(); }, location.origin);
</span><ins>+requestHeaders("Fetch with POST with URLSearchParams body", url, "POST", function() { return new URLSearchParams("name=value"); }, location.origin, "10");
</ins><span class="cx"> requestHeaders("Fetch with POST with Blob body", url, "POST", new Blob(["Test"]), location.origin, "4");
</span><span class="cx"> requestHeaders("Fetch with POST with ArrayBuffer body", url, "POST", new ArrayBuffer(4), location.origin, "4");
</span><span class="cx"> requestHeaders("Fetch with POST with Uint8Array body", url, "POST", new Uint8Array(4), location.origin, "4");
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapibasicrequestuploadexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload-expected.txt (0 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload-expected.txt         (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload-expected.txt        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -0,0 +1,13 @@
</span><ins>+
+PASS Fetch with PUT with body
+PASS Fetch with POST with text body
+PASS Fetch with POST with URLSearchParams body
+PASS Fetch with POST with Blob body
+PASS Fetch with POST with ArrayBuffer body
+PASS Fetch with POST with Uint8Array body
+PASS Fetch with POST with Int8Array body
+PASS Fetch with POST with Float32Array body
+PASS Fetch with POST with Float64Array body
+PASS Fetch with POST with DataView body
+PASS Fetch with POST with Blob body with mime type
+
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapibasicrequestuploadworkerexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload-worker-expected.txt (0 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload-worker-expected.txt         (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload-worker-expected.txt        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -0,0 +1,13 @@
</span><ins>+
+PASS Fetch with PUT with body
+PASS Fetch with POST with text body
+PASS Fetch with POST with URLSearchParams body
+PASS Fetch with POST with Blob body
+PASS Fetch with POST with ArrayBuffer body
+PASS Fetch with POST with Uint8Array body
+PASS Fetch with POST with Int8Array body
+PASS Fetch with POST with Float32Array body
+PASS Fetch with POST with Float64Array body
+PASS Fetch with POST with DataView body
+PASS Fetch with POST with Blob body with mime type
+
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapibasicrequestuploadworkerhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload-worker.html (0 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload-worker.html         (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload-worker.html        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -0,0 +1,14 @@
</span><ins>+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Fetch in worker: Upload</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ </head>
+ <body>
+ <script>
+ fetch_tests_from_worker(new Worker("request-upload.js"));
+ </script>
+ </body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapibasicrequestuploadhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload.html (0 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload.html         (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload.html        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -0,0 +1,13 @@
</span><ins>+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Fetch: Uploading content</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="../resources/utils.js"></script>
+ </head>
+ <body>
+ <script src="request-upload.js"></script>
+ </body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapibasicrequestuploadjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload.js (0 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload.js         (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload.js        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -0,0 +1,35 @@
</span><ins>+if (this.document === undefined) {
+ importScripts("/resources/testharness.js");
+ importScripts("../resources/utils.js");
+}
+
+function testUpload(desc, url, method, body, expectedBody) {
+ var requestInit = {"method": method}
+ promise_test(function(test){
+ if (typeof body === "function")
+ body = body();
+ if (body)
+ requestInit["body"] = body;
+ return fetch(url, requestInit).then(function(resp) {
+ return resp.text().then((text)=> {
+ assert_equals(text, expectedBody);
+ });
+ });
+ }, desc);
+}
+
+var url = RESOURCES_DIR + "echo-content.py"
+
+testUpload("Fetch with PUT with body", url, "PUT", "Request's body", "Request's body");
+testUpload("Fetch with POST with text body", url, "POST", "Request's body", "Request's body");
+testUpload("Fetch with POST with URLSearchParams body", url, "POST", function() { return new URLSearchParams("name=value"); }, "name=value");
+testUpload("Fetch with POST with Blob body", url, "POST", new Blob(["Test"]), "Test");
+testUpload("Fetch with POST with ArrayBuffer body", url, "POST", new ArrayBuffer(4), "\0\0\0\0");
+testUpload("Fetch with POST with Uint8Array body", url, "POST", new Uint8Array(4), "\0\0\0\0");
+testUpload("Fetch with POST with Int8Array body", url, "POST", new Int8Array(4), "\0\0\0\0");
+testUpload("Fetch with POST with Float32Array body", url, "POST", new Float32Array(1), "\0\0\0\0");
+testUpload("Fetch with POST with Float64Array body", url, "POST", new Float64Array(1), "\0\0\0\0\0\0\0\0");
+testUpload("Fetch with POST with DataView body", url, "POST", new DataView(new ArrayBuffer(8), 0, 4), "\0\0\0\0");
+testUpload("Fetch with POST with Blob body with mime type", url, "POST", new Blob(["Test"], { type: "text/maybe" }), "Test");
+
+done();
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapirequestrequestconsumeemptyexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume-empty-expected.txt (206631 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume-empty-expected.txt        2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume-empty-expected.txt        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -8,4 +8,7 @@
</span><span class="cx"> PASS Consume empty text request body as arrayBuffer
</span><span class="cx"> PASS Consume empty blob request body as text
</span><span class="cx"> PASS Consume empty text request body as text
</span><ins>+PASS Consume empty URLSearchParams request body as text
+FAIL Consume empty FormData request body as text promise_test: Unhandled rejection with value: undefined
+PASS Consume empty ArrayBuffer request body as text
</ins><span class="cx">
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapirequestrequestconsumeemptyhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume-empty.html (206631 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume-empty.html        2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume-empty.html        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -98,6 +98,9 @@
</span><span class="cx"> checkRequestWithEmptyBody("text", "", false);
</span><span class="cx"> checkRequestWithEmptyBody("blob", new Blob([], { "type" : "text/plain" }), true);
</span><span class="cx"> checkRequestWithEmptyBody("text", "", true);
</span><ins>+ checkRequestWithEmptyBody("URLSearchParams", new URLSearchParams(""), true);
+ checkRequestWithEmptyBody("FormData", new FormData(), true);
+ checkRequestWithEmptyBody("ArrayBuffer", new ArrayBuffer(), true);
</ins><span class="cx"> </script>
</span><span class="cx"> </body>
</span><span class="cx"> </html>
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapirequestrequestinit002expectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-002-expected.txt (206631 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-002-expected.txt        2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-002-expected.txt        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -5,5 +5,5 @@
</span><span class="cx"> PASS Initialize Request's body with application/octet-binary
</span><span class="cx"> FAIL Initialize Request's body with multipart/form-data promise_test: Unhandled rejection with value: undefined
</span><span class="cx"> PASS Initialize Request's body with text/plain;charset=UTF-8
</span><del>-FAIL Initialize Request's body with application/x-www-form-urlencoded;charset=UTF-8 Type error
</del><ins>+PASS Initialize Request's body with application/x-www-form-urlencoded;charset=UTF-8
</ins><span class="cx">
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapiresourcesechocontentpy"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/echo-content.py (0 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/echo-content.py         (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/echo-content.py        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -0,0 +1,9 @@
</span><ins>+def main(request, response):
+
+ headers = [("X-Request-Method", request.method),
+ ("X-Request-Content-Length", request.headers.get("Content-Length", "NO")),
+ ("X-Request-Content-Type", request.headers.get("Content-Type", "NO"))]
+
+ content = request.body
+
+ return headers, content
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapiresponseresponseconsumeemptyexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-empty-expected.txt (206631 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-empty-expected.txt        2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-empty-expected.txt        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -8,4 +8,7 @@
</span><span class="cx"> PASS Consume empty text response body as arrayBuffer
</span><span class="cx"> PASS Consume empty blob response body as text
</span><span class="cx"> PASS Consume empty text response body as text
</span><ins>+PASS Consume empty URLSearchParams response body as text
+FAIL Consume empty FormData response body as text promise_test: Unhandled rejection with value: undefined
+PASS Consume empty ArrayBuffer response body as text
</ins><span class="cx">
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapiresponseresponseconsumeemptyhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-empty.html (206631 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-empty.html        2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-empty.html        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -93,11 +93,13 @@
</span><span class="cx"> }, "Consume empty " + bodyType + " response body as " + (asText ? "text" : "arrayBuffer"));
</span><span class="cx"> }
</span><span class="cx">
</span><del>- // FIXME: Add BufferSource, FormData and URLSearchParams.
</del><span class="cx"> checkResponseWithEmptyBody("blob", new Blob([], { "type" : "text/plain" }), false);
</span><span class="cx"> checkResponseWithEmptyBody("text", "", false);
</span><span class="cx"> checkResponseWithEmptyBody("blob", new Blob([], { "type" : "text/plain" }), true);
</span><span class="cx"> checkResponseWithEmptyBody("text", "", true);
</span><ins>+ checkResponseWithEmptyBody("URLSearchParams", new URLSearchParams(""), true);
+ checkResponseWithEmptyBody("FormData", new FormData(), true);
+ checkResponseWithEmptyBody("ArrayBuffer", new ArrayBuffer(), true);
</ins><span class="cx"> </script>
</span><span class="cx"> </body>
</span><span class="cx"> </html>
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapiresponseresponseconsumeexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-expected.txt (206631 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-expected.txt        2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-expected.txt        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -1,9 +1,12 @@
</span><span class="cx">
</span><del>-PASS Consume response's body as text
-PASS Consume response's body as blob
-PASS Consume response's body as arrayBuffer
-PASS Consume response's body as json
-FAIL Consume response's body as formData promise_test: Unhandled rejection with value: "Not implemented"
</del><ins>+PASS Consume text response's body as text
+PASS Consume text response's body as blob
+PASS Consume text response's body as arrayBuffer
+PASS Consume text response's body as json
+FAIL Consume formdata response's body as formData promise_test: Unhandled rejection with value: "Not implemented"
+PASS Consume URLSearchParams response's body as text
+PASS Consume URLSearchParams response's body as blob
+PASS Consume URLSearchParams response's body as arrayBuffer
</ins><span class="cx"> PASS Consume blob response's body as blob
</span><span class="cx"> PASS Consume blob response's body as text
</span><span class="cx"> PASS Consume blob response's body as json
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapiresponseresponseconsumestreamexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-stream-expected.txt (206631 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-stream-expected.txt        2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-stream-expected.txt        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -3,6 +3,7 @@
</span><span class="cx"> PASS Read empty blob response's body as readableStream
</span><span class="cx"> PASS Read blob response's body as readableStream
</span><span class="cx"> PASS Read text response's body as readableStream
</span><ins>+PASS Read text response's body as readableStream
</ins><span class="cx"> PASS Read array buffer response's body as readableStream
</span><span class="cx"> FAIL Read form data response's body as readableStream promise_test: Unhandled rejection with value: "not implemented"
</span><span class="cx"> PASS Getting an error Response stream
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapiresponseresponseconsumestreamhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-stream.html (206631 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-stream.html        2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-stream.html        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -28,6 +28,8 @@
</span><span class="cx"> formData.append("name", "value");
</span><span class="cx"> var textData = JSON.stringify("This is response's body");
</span><span class="cx"> var blob = new Blob([textData], { "type" : "text/plain" });
</span><ins>+var urlSearchParamsData = "name=value";
+var urlSearchParams = new URLSearchParams(urlSearchParamsData);
</ins><span class="cx">
</span><span class="cx"> promise_test(function(test) {
</span><span class="cx"> var response = new Response(blob);
</span><span class="lines">@@ -40,6 +42,11 @@
</span><span class="cx"> }, "Read text response's body as readableStream");
</span><span class="cx">
</span><span class="cx"> promise_test(function(test) {
</span><ins>+ var response = new Response(urlSearchParams);
+ return validateStreamFromString(response.body.getReader(), urlSearchParamsData);
+}, "Read text response's body as readableStream");
+
+promise_test(function(test) {
</ins><span class="cx"> var arrayBuffer = new ArrayBuffer(textData.length);
</span><span class="cx"> var int8Array = new Int8Array(arrayBuffer);
</span><span class="cx"> for (var cptr = 0; cptr < textData.length; cptr++)
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapiresponseresponseconsumehtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume.html (206631 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume.html        2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume.html        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -63,12 +63,12 @@
</span><span class="cx"> });
</span><span class="cx"> }
</span><span class="cx">
</span><del>- function checkResponseBody(body, bodyType, checkFunction) {
</del><ins>+ function checkResponseBody(body, bodyType, bodyConsumingType, checkFunction) {
</ins><span class="cx"> promise_test(function(test) {
</span><span class="cx"> var response = new Response(body, { "headers": [["Content-Type", "text/PLAIN"]] });
</span><span class="cx"> assert_false(response.bodyUsed, "bodyUsed is false at init");
</span><span class="cx"> return checkFunction(response, body);
</span><del>- }, "Consume response's body as " + bodyType);
</del><ins>+ }, "Consume " + bodyType + " response's body as " + bodyConsumingType);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> var formData = new FormData();
</span><span class="lines">@@ -75,12 +75,17 @@
</span><span class="cx"> formData.append("name", "value");
</span><span class="cx"> var textData = JSON.stringify("This is response's body");
</span><span class="cx"> var blob = new Blob([textData], { "type" : "text/plain" });
</span><ins>+ var urlSearchParamsData = "name=value";
+ var urlSearchParams = new URLSearchParams(urlSearchParamsData);
</ins><span class="cx">
</span><del>- checkResponseBody(textData, "text", checkBodyText);
- checkResponseBody(textData, "blob", function(response, body) { checkBodyBlob(response, body, true); });
- checkResponseBody(textData, "arrayBuffer", checkBodyArrayBuffer);
- checkResponseBody(textData, "json", checkBodyJSON);
- checkResponseBody(formData, "formData", checkBodyFormData);
</del><ins>+ checkResponseBody(textData, "text", "text", checkBodyText);
+ checkResponseBody(textData, "text", "blob", function(response, body) { checkBodyBlob(response, body, true); });
+ checkResponseBody(textData, "text", "arrayBuffer", checkBodyArrayBuffer);
+ checkResponseBody(textData, "text", "json", checkBodyJSON);
+ checkResponseBody(formData, "formdata", "formData", checkBodyFormData);
+ checkResponseBody(urlSearchParams, "URLSearchParams", "text", function(response) { checkBodyText(response, urlSearchParams); });
+ checkResponseBody(urlSearchParams, "URLSearchParams", "blob", function(response, body) { checkBodyBlob(response, urlSearchParamsData, false); });
+ checkResponseBody(urlSearchParams, "URLSearchParams", "arrayBuffer", function(response) { checkBodyArrayBuffer(response, urlSearchParamsData); });
</ins><span class="cx">
</span><span class="cx"> function checkBlobResponseBody(blobBody, blobData, bodyType, checkFunction) {
</span><span class="cx"> promise_test(function(test) {
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapiresponseresponseinit002expectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-init-002-expected.txt (206631 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-init-002-expected.txt        2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-init-002-expected.txt        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -2,7 +2,7 @@
</span><span class="cx"> PASS Initialize Response with headers values
</span><span class="cx"> PASS Initialize Response's body with application/octet-binary
</span><span class="cx"> FAIL Initialize Response's body with multipart/form-data promise_test: Unhandled rejection with value: undefined
</span><del>-FAIL Initialize Response's body with application/x-www-form-urlencoded;charset=UTF-8 assert_true: Content-Type header should be "application/x-www-form-urlencoded;charset=UTF-8" expected true got null
</del><ins>+PASS Initialize Response's body with application/x-www-form-urlencoded;charset=UTF-8
</ins><span class="cx"> PASS Initialize Response's body with text/plain;charset=UTF-8
</span><span class="cx"> PASS Read Response's body as readableStream
</span><span class="cx"> PASS Testing empty Response Content-Type header
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (206631 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/Source/WebCore/ChangeLog        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2016-09-30 Youenn Fablet <youennf@gmail.com>
+
+ [Fetch API] Add support for URLSearchParams body
+ https://bugs.webkit.org/show_bug.cgi?id=162667
+
+ Reviewed by Alex Christensen.
+
+ Tests: imported/w3c/web-platform-tests/fetch/api/basic/request-upload-worker.html
+ imported/w3c/web-platform-tests/fetch/api/basic/request-upload.html
+
+ * Modules/fetch/FetchBody.cpp:
+ (WebCore::extractBytesFromText): Moving to a static function that should be moved to a String method.
+ (WebCore::FetchBody::FetchBody): Adding constructor for URLSearchParams.
+ (WebCore::FetchBody::extract): Adding URLSearchParams body initialization.
+ (WebCore::FetchBody::consume): Consuming URLSearchParams bodies.
+ (WebCore::FetchBody::consumeAsStream): Ditto.
+ (WebCore::FetchBody::consumeText): Updated to take a parameter to handle both text and URLSearchParams bodies.
+ (WebCore::FetchBody::bodyForInternalRequest): Add URLSearchParams body upload.
+ (WebCore::FetchBody::clone): Add URLSearchParams body cloning
+ * Modules/fetch/FetchBody.h:
+ (WebCore::FetchBody::urlSearchParamsBody):
+ * html/URLSearchParams.cpp:
+ (WebCore::URLSearchParams::toString):
+ * html/URLSearchParams.h:
+
</ins><span class="cx"> 2016-09-29 Simon Fraser <simon.fraser@apple.com>
</span><span class="cx">
</span><span class="cx"> Re-order the arguments to drawPattern() functions
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesfetchFetchBodycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.cpp (206631 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/fetch/FetchBody.cpp        2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.cpp        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -41,11 +41,21 @@
</span><span class="cx"> #include "JSBlob.h"
</span><span class="cx"> #include "JSDOMFormData.h"
</span><span class="cx"> #include "JSReadableStream.h"
</span><ins>+#include "JSURLSearchParams.h"
</ins><span class="cx"> #include "ReadableStreamSource.h"
</span><span class="cx"> #include <runtime/ArrayBufferView.h>
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><ins>+// FIXME: This implementation is not efficient and we should probably use UTF8Encoding().
+static Vector<uint8_t> extractBytesFromText(const String& text)
+{
+ CString data = text.utf8();
+ Vector<uint8_t> value(data.length());
+ memcpy(value.data(), data.data(), data.length());
+ return value;
+}
+
</ins><span class="cx"> FetchBody::FetchBody(Ref<const Blob>&& blob)
</span><span class="cx"> : m_type(Type::Blob)
</span><span class="cx"> , m_data(WTFMove(blob))
</span><span class="lines">@@ -79,6 +89,13 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+FetchBody::FetchBody(Ref<const URLSearchParams>&& url)
+ : m_type(Type::URLSeachParams)
+ , m_data(WTFMove(url))
+ , m_contentType(ASCIILiteral("application/x-www-form-urlencoded;charset=UTF-8"))
+{
+}
+
</ins><span class="cx"> FetchBody::FetchBody(Type type, const String& contentType, const FetchBodyConsumer& consumer)
</span><span class="cx"> : m_type(type)
</span><span class="cx"> , m_contentType(contentType)
</span><span class="lines">@@ -96,6 +113,8 @@
</span><span class="cx"> }
</span><span class="cx"> if (value.isString())
</span><span class="cx"> return FetchBody(value.toWTFString(&state));
</span><ins>+ if (value.inherits(JSURLSearchParams::info()))
+ return FetchBody(*JSURLSearchParams::toWrapped(value));
</ins><span class="cx"> if (value.inherits(JSReadableStream::info()))
</span><span class="cx"> return { Type::ReadableStream };
</span><span class="cx"> if (value.inherits(JSC::JSArrayBuffer::info())) {
</span><span class="lines">@@ -185,8 +204,11 @@
</span><span class="cx"> consumeArrayBufferView(WTFMove(promise));
</span><span class="cx"> return;
</span><span class="cx"> case Type::Text:
</span><del>- consumeText(WTFMove(promise));
</del><ins>+ consumeText(WTFMove(promise), textBody());
</ins><span class="cx"> return;
</span><ins>+ case Type::URLSeachParams:
+ consumeText(WTFMove(promise), urlSearchParamsBody().toString());
+ return;
</ins><span class="cx"> case Type::Blob:
</span><span class="cx"> consumeBlob(owner, WTFMove(promise));
</span><span class="cx"> return;
</span><span class="lines">@@ -225,11 +247,17 @@
</span><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx"> case Type::Text: {
</span><del>- Vector<uint8_t> data = extractFromText();
</del><ins>+ Vector<uint8_t> data = extractBytesFromText(textBody());
</ins><span class="cx"> closeStream = source.enqueue(ArrayBuffer::tryCreate(data.data(), data.size()));
</span><span class="cx"> m_data = nullptr;
</span><span class="cx"> break;
</span><span class="cx"> }
</span><ins>+ case Type::URLSeachParams: {
+ Vector<uint8_t> data = extractBytesFromText(urlSearchParamsBody().toString());
+ closeStream = source.enqueue(ArrayBuffer::tryCreate(data.data(), data.size()));
+ m_data = nullptr;
+ break;
+ }
</ins><span class="cx"> case Type::Blob:
</span><span class="cx"> owner.loadBlob(blobBody(), nullptr);
</span><span class="cx"> m_data = nullptr;
</span><span class="lines">@@ -262,9 +290,9 @@
</span><span class="cx"> m_data = nullptr;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void FetchBody::consumeText(Ref<DeferredPromise>&& promise)
</del><ins>+void FetchBody::consumeText(Ref<DeferredPromise>&& promise, const String& text)
</ins><span class="cx"> {
</span><del>- Vector<uint8_t> data = extractFromText();
</del><ins>+ Vector<uint8_t> data = extractBytesFromText(text);
</ins><span class="cx"> m_consumer.resolveWithData(WTFMove(promise), data.data(), data.size());
</span><span class="cx"> m_data = nullptr;
</span><span class="cx"> }
</span><span class="lines">@@ -276,16 +304,6 @@
</span><span class="cx"> m_data = nullptr;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-Vector<uint8_t> FetchBody::extractFromText() const
-{
- ASSERT(m_type == Type::Text);
- // FIXME: This double allocation is not efficient. Might want to fix that at WTFString level.
- CString data = textBody().utf8();
- Vector<uint8_t> value(data.length());
- memcpy(value.data(), data.data(), data.length());
- return value;
-}
-
</del><span class="cx"> void FetchBody::loadingFailed()
</span><span class="cx"> {
</span><span class="cx"> if (m_consumePromise) {
</span><span class="lines">@@ -308,6 +326,8 @@
</span><span class="cx"> return nullptr;
</span><span class="cx"> case Type::Text:
</span><span class="cx"> return FormData::create(UTF8Encoding().encode(textBody(), EntitiesForUnencodables));
</span><ins>+ case Type::URLSeachParams:
+ return FormData::create(UTF8Encoding().encode(urlSearchParamsBody().toString(), EntitiesForUnencodables));
</ins><span class="cx"> case Type::Blob: {
</span><span class="cx"> RefPtr<FormData> body = FormData::create();
</span><span class="cx"> body->appendBlob(blobBody().url());
</span><span class="lines">@@ -350,6 +370,9 @@
</span><span class="cx"> case Type::Text:
</span><span class="cx"> clone.m_data = textBody();
</span><span class="cx"> break;
</span><ins>+ case Type::URLSeachParams:
+ clone.m_data = urlSearchParamsBody();
+ break;
</ins><span class="cx"> case Type::Loaded:
</span><span class="cx"> case Type::None:
</span><span class="cx"> case Type::Loading:
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesfetchFetchBodyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.h (206631 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/fetch/FetchBody.h        2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.h        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -36,6 +36,7 @@
</span><span class="cx"> #include "FetchLoader.h"
</span><span class="cx"> #include "FormData.h"
</span><span class="cx"> #include "JSDOMPromise.h"
</span><ins>+#include "URLSearchParams.h"
</ins><span class="cx"> #include <wtf/Variant.h>
</span><span class="cx">
</span><span class="cx"> namespace JSC {
</span><span class="lines">@@ -79,7 +80,7 @@
</span><span class="cx">
</span><span class="cx"> RefPtr<FormData> bodyForInternalRequest(ScriptExecutionContext&) const;
</span><span class="cx">
</span><del>- enum class Type { None, ArrayBuffer, ArrayBufferView, Blob, FormData, Text, Loading, Loaded, ReadableStream };
</del><ins>+ enum class Type { None, ArrayBuffer, ArrayBufferView, Blob, FormData, Text, URLSeachParams, Loading, Loaded, ReadableStream };
</ins><span class="cx"> Type type() const { return m_type; }
</span><span class="cx">
</span><span class="cx"> FetchBodyConsumer& consumer() { return m_consumer; }
</span><span class="lines">@@ -94,15 +95,15 @@
</span><span class="cx"> FetchBody(Ref<const ArrayBufferView>&&);
</span><span class="cx"> FetchBody(DOMFormData&, Document&);
</span><span class="cx"> FetchBody(String&&);
</span><ins>+ FetchBody(Ref<const URLSearchParams>&&);
</ins><span class="cx"> FetchBody(Type, const String&, const FetchBodyConsumer&);
</span><span class="cx"> FetchBody(Type type) : m_type(type) { }
</span><span class="cx">
</span><span class="cx"> void consume(FetchBodyOwner&, Ref<DeferredPromise>&&);
</span><span class="cx">
</span><del>- Vector<uint8_t> extractFromText() const;
</del><span class="cx"> void consumeArrayBuffer(Ref<DeferredPromise>&&);
</span><span class="cx"> void consumeArrayBufferView(Ref<DeferredPromise>&&);
</span><del>- void consumeText(Ref<DeferredPromise>&&);
</del><ins>+ void consumeText(Ref<DeferredPromise>&&, const String&);
</ins><span class="cx"> void consumeBlob(FetchBodyOwner&, Ref<DeferredPromise>&&);
</span><span class="cx">
</span><span class="cx"> const Blob& blobBody() const { return std::experimental::get<Ref<const Blob>>(m_data).get(); }
</span><span class="lines">@@ -112,11 +113,11 @@
</span><span class="cx"> const ArrayBufferView& arrayBufferViewBody() const { return std::experimental::get<Ref<const ArrayBufferView>>(m_data).get(); }
</span><span class="cx"> String& textBody() { return std::experimental::get<String>(m_data); }
</span><span class="cx"> const String& textBody() const { return std::experimental::get<String>(m_data); }
</span><ins>+ const URLSearchParams& urlSearchParamsBody() const { return std::experimental::get<Ref<const URLSearchParams>>(m_data).get(); }
</ins><span class="cx">
</span><span class="cx"> Type m_type { Type::None };
</span><span class="cx">
</span><del>- // FIXME: Add support for URLSearchParams.
- std::experimental::variant<std::nullptr_t, Ref<const Blob>, Ref<FormData>, Ref<const ArrayBuffer>, Ref<const ArrayBufferView>, String> m_data;
</del><ins>+ std::experimental::variant<std::nullptr_t, Ref<const Blob>, Ref<FormData>, Ref<const ArrayBuffer>, Ref<const ArrayBufferView>, Ref<const URLSearchParams>, String> m_data;
</ins><span class="cx"> String m_contentType;
</span><span class="cx">
</span><span class="cx"> FetchBodyConsumer m_consumer { FetchBodyConsumer::Type::None };
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlURLSearchParamscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/URLSearchParams.cpp (206631 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/URLSearchParams.cpp        2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/Source/WebCore/html/URLSearchParams.cpp        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -106,7 +106,7 @@
</span><span class="cx"> updateURL();
</span><span class="cx"> }
</span><span class="cx">
</span><del>-String URLSearchParams::toString()
</del><ins>+String URLSearchParams::toString() const
</ins><span class="cx"> {
</span><span class="cx"> return URLParser::serialize(m_pairs);
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlURLSearchParamsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/URLSearchParams.h (206631 => 206632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/URLSearchParams.h        2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/Source/WebCore/html/URLSearchParams.h        2016-09-30 08:04:52 UTC (rev 206632)
</span><span class="lines">@@ -42,7 +42,7 @@
</span><span class="cx"> Vector<String> getAll(const String& name) const;
</span><span class="cx"> bool has(const String& name) const;
</span><span class="cx"> void set(const String& name, const String& value);
</span><del>- String toString();
</del><ins>+ String toString() const;
</ins><span class="cx"> operator const Vector<std::pair<String, String>>&() { return m_pairs; }
</span><span class="cx"> void updateFromAssociatedURL();
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>