Title: [220779] trunk
Revision
220779
Author
[email protected]
Date
2017-08-15 18:23:50 -0700 (Tue, 15 Aug 2017)

Log Message

Fetch / Beacon: Use "application/octet-stream" Content-Type for payloads of type ArrayBuffer / ArrayBufferView
https://bugs.webkit.org/show_bug.cgi?id=175600

Reviewed by Youenn Fablet.

LayoutTests/imported/w3c:

* web-platform-tests/beacon/headers/header-content-type-expected.txt:
* web-platform-tests/fetch/api/basic/request-headers.any-expected.txt:
* web-platform-tests/fetch/api/basic/request-headers.any.worker-expected.txt:

Source/WebCore:

Use "application/octet-stream" Content-Type for payloads of type ArrayBuffer / ArrayBufferView in Fetch & Beacon.
If we don't set a Content-Type header, our underlying network stack is going to add a "application/x-www-form-urlencoded"
Content-Type header, which is worse.

Chrome is already using "application/octet-stream" Content-Type in Beacon, but use no Content-Type in Fetch.
The Fetch/Beacon specification says we should have no Content-Type header in this case but this is unfortunately
not something we can support at the moment. Using "application/octet-stream" Content-Type for now seems like the
lesser evil.

Test: http/wpt/fetch/fetch-request-arraybuffer-content-type.html

* Modules/fetch/FetchBody.cpp:
(WebCore::FetchBody::extract):
* platform/network/HTTPHeaderValues.cpp:
(WebCore::HTTPHeaderValues::octetStreamContentType):
* platform/network/HTTPHeaderValues.h:

LayoutTests:

* http/wpt/fetch/fetch-request-arraybuffer-content-type-expected.txt: Added.
* http/wpt/fetch/fetch-request-arraybuffer-content-type.html: Added.
* platform/mac-highsierra/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.any-expected.txt:
* platform/mac-highsierra/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.any.worker-expected.txt:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (220778 => 220779)


--- trunk/LayoutTests/ChangeLog	2017-08-16 01:10:01 UTC (rev 220778)
+++ trunk/LayoutTests/ChangeLog	2017-08-16 01:23:50 UTC (rev 220779)
@@ -1,3 +1,15 @@
+2017-08-15  Chris Dumez  <[email protected]>
+
+        Fetch / Beacon: Use "application/octet-stream" Content-Type for payloads of type ArrayBuffer / ArrayBufferView
+        https://bugs.webkit.org/show_bug.cgi?id=175600
+
+        Reviewed by Youenn Fablet.
+
+        * http/wpt/fetch/fetch-request-arraybuffer-content-type-expected.txt: Added.
+        * http/wpt/fetch/fetch-request-arraybuffer-content-type.html: Added.
+        * platform/mac-highsierra/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.any-expected.txt:
+        * platform/mac-highsierra/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.any.worker-expected.txt:
+
 2017-08-15  Matt Lewis  <[email protected]>
 
         Skipped media/modern-media-controls/time-labels-support/elapsed-time.html.

Added: trunk/LayoutTests/http/wpt/fetch/fetch-request-arraybuffer-content-type-expected.txt (0 => 220779)


--- trunk/LayoutTests/http/wpt/fetch/fetch-request-arraybuffer-content-type-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/fetch/fetch-request-arraybuffer-content-type-expected.txt	2017-08-16 01:23:50 UTC (rev 220779)
@@ -0,0 +1,3 @@
+
+PASS Content-Type header for payload of ArrayBuffer type should be 'application/octet-stream' 
+

Added: trunk/LayoutTests/http/wpt/fetch/fetch-request-arraybuffer-content-type.html (0 => 220779)


--- trunk/LayoutTests/http/wpt/fetch/fetch-request-arraybuffer-content-type.html	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/fetch/fetch-request-arraybuffer-content-type.html	2017-08-16 01:23:50 UTC (rev 220779)
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script src=""
+<script>
+test(function(t) {
+  let request = new Request("http://localhost", { method: "POST", body: new ArrayBuffer() });
+  assert_equals(request.headers.get('Content-Type'), "application/octet-stream");
+}, "Content-Type header for payload of ArrayBuffer type should be 'application/octet-stream'");
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (220778 => 220779)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2017-08-16 01:10:01 UTC (rev 220778)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2017-08-16 01:23:50 UTC (rev 220779)
@@ -1,5 +1,16 @@
 2017-08-15  Chris Dumez  <[email protected]>
 
+        Fetch / Beacon: Use "application/octet-stream" Content-Type for payloads of type ArrayBuffer / ArrayBufferView
+        https://bugs.webkit.org/show_bug.cgi?id=175600
+
+        Reviewed by Youenn Fablet.
+
+        * web-platform-tests/beacon/headers/header-content-type-expected.txt:
+        * web-platform-tests/fetch/api/basic/request-headers.any-expected.txt:
+        * web-platform-tests/fetch/api/basic/request-headers.any.worker-expected.txt:
+
+2017-08-15  Chris Dumez  <[email protected]>
+
         Re-sync DOM Web-Platform-Tests from upstream
         https://bugs.webkit.org/show_bug.cgi?id=175588
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/beacon/headers/header-content-type-expected.txt (220778 => 220779)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/beacon/headers/header-content-type-expected.txt	2017-08-16 01:10:01 UTC (rev 220778)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/beacon/headers/header-content-type-expected.txt	2017-08-16 01:23:50 UTC (rev 220779)
@@ -1,7 +1,7 @@
 
 PASS Test content-type header for a body string 
-FAIL Test content-type header for a body ArrayBufferView assert_equals: Correct Content-Type header result expected "" but got "application/x-www-form-urlencoded"
-FAIL Test content-type header for a body ArrayBuffer assert_equals: Correct Content-Type header result expected "" but got "application/x-www-form-urlencoded"
+FAIL Test content-type header for a body ArrayBufferView assert_equals: Correct Content-Type header result expected "" but got "application/octet-stream"
+FAIL Test content-type header for a body ArrayBuffer assert_equals: Correct Content-Type header result expected "" but got "application/octet-stream"
 PASS Test content-type header for a body Blob 
 PASS Test content-type header for a body FormData 
 PASS Test content-type header for a body URLSearchParams 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.any-expected.txt (220778 => 220779)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.any-expected.txt	2017-08-16 01:10:01 UTC (rev 220778)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.any-expected.txt	2017-08-16 01:23:50 UTC (rev 220779)
@@ -8,12 +8,12 @@
 PASS Fetch with POST with FormData body 
 PASS Fetch with POST with URLSearchParams body 
 FAIL Fetch with POST with Blob body assert_equals: Request should have header content-type: null expected (object) null but got (string) ""
-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"
-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"
-FAIL Fetch with POST with Int8Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
-FAIL Fetch with POST with Float32Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
-FAIL Fetch with POST with Float64Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
-FAIL Fetch with POST with DataView body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
+FAIL Fetch with POST with ArrayBuffer body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
+FAIL Fetch with POST with Uint8Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
+FAIL Fetch with POST with Int8Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
+FAIL Fetch with POST with Float32Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
+FAIL Fetch with POST with Float64Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
+FAIL Fetch with POST with DataView body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
 PASS Fetch with POST with Blob body with mime type 
 FAIL Fetch with Chicken assert_equals: Request should have header content-length: null expected (object) null but got (string) "0"
 PASS Fetch with Chicken with body 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.any.worker-expected.txt (220778 => 220779)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.any.worker-expected.txt	2017-08-16 01:10:01 UTC (rev 220778)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.any.worker-expected.txt	2017-08-16 01:23:50 UTC (rev 220779)
@@ -8,12 +8,12 @@
 FAIL Fetch with POST with FormData body Can't find variable: FormData
 PASS Fetch with POST with URLSearchParams body 
 FAIL Fetch with POST with Blob body assert_equals: Request should have header content-type: null expected (object) null but got (string) ""
-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"
-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"
-FAIL Fetch with POST with Int8Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
-FAIL Fetch with POST with Float32Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
-FAIL Fetch with POST with Float64Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
-FAIL Fetch with POST with DataView body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
+FAIL Fetch with POST with ArrayBuffer body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
+FAIL Fetch with POST with Uint8Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
+FAIL Fetch with POST with Int8Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
+FAIL Fetch with POST with Float32Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
+FAIL Fetch with POST with Float64Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
+FAIL Fetch with POST with DataView body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
 PASS Fetch with POST with Blob body with mime type 
 FAIL Fetch with Chicken assert_equals: Request should have header content-length: null expected (object) null but got (string) "0"
 PASS Fetch with Chicken with body 

Modified: trunk/LayoutTests/platform/mac-highsierra/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.any-expected.txt (220778 => 220779)


--- trunk/LayoutTests/platform/mac-highsierra/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.any-expected.txt	2017-08-16 01:10:01 UTC (rev 220778)
+++ trunk/LayoutTests/platform/mac-highsierra/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.any-expected.txt	2017-08-16 01:23:50 UTC (rev 220779)
@@ -7,13 +7,13 @@
 PASS Fetch with POST with text body 
 PASS Fetch with POST with FormData body 
 PASS Fetch with POST with URLSearchParams body 
-PASS Fetch with POST with Blob body 
-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"
-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"
-FAIL Fetch with POST with Int8Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
-FAIL Fetch with POST with Float32Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
-FAIL Fetch with POST with Float64Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
-FAIL Fetch with POST with DataView body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
+FAIL Fetch with POST with Blob body assert_equals: Request should have header content-type: null expected (object) null but got (string) ""
+FAIL Fetch with POST with ArrayBuffer body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
+FAIL Fetch with POST with Uint8Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
+FAIL Fetch with POST with Int8Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
+FAIL Fetch with POST with Float32Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
+FAIL Fetch with POST with Float64Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
+FAIL Fetch with POST with DataView body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
 PASS Fetch with POST with Blob body with mime type 
 FAIL Fetch with Chicken assert_equals: Request should have header content-length: null expected (object) null but got (string) "0"
 PASS Fetch with Chicken with body 

Modified: trunk/LayoutTests/platform/mac-highsierra/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.any.worker-expected.txt (220778 => 220779)


--- trunk/LayoutTests/platform/mac-highsierra/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.any.worker-expected.txt	2017-08-16 01:10:01 UTC (rev 220778)
+++ trunk/LayoutTests/platform/mac-highsierra/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.any.worker-expected.txt	2017-08-16 01:23:50 UTC (rev 220779)
@@ -7,13 +7,13 @@
 PASS Fetch with POST with text body 
 FAIL Fetch with POST with FormData body Can't find variable: FormData
 PASS Fetch with POST with URLSearchParams body 
-PASS Fetch with POST with Blob body 
-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"
-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"
-FAIL Fetch with POST with Int8Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
-FAIL Fetch with POST with Float32Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
-FAIL Fetch with POST with Float64Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
-FAIL Fetch with POST with DataView body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
+FAIL Fetch with POST with Blob body assert_equals: Request should have header content-type: null expected (object) null but got (string) ""
+FAIL Fetch with POST with ArrayBuffer body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
+FAIL Fetch with POST with Uint8Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
+FAIL Fetch with POST with Int8Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
+FAIL Fetch with POST with Float32Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
+FAIL Fetch with POST with Float64Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
+FAIL Fetch with POST with DataView body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/octet-stream"
 PASS Fetch with POST with Blob body with mime type 
 FAIL Fetch with Chicken assert_equals: Request should have header content-length: null expected (object) null but got (string) "0"
 PASS Fetch with Chicken with body 

Modified: trunk/Source/WebCore/ChangeLog (220778 => 220779)


--- trunk/Source/WebCore/ChangeLog	2017-08-16 01:10:01 UTC (rev 220778)
+++ trunk/Source/WebCore/ChangeLog	2017-08-16 01:23:50 UTC (rev 220779)
@@ -1,3 +1,27 @@
+2017-08-15  Chris Dumez  <[email protected]>
+
+        Fetch / Beacon: Use "application/octet-stream" Content-Type for payloads of type ArrayBuffer / ArrayBufferView
+        https://bugs.webkit.org/show_bug.cgi?id=175600
+
+        Reviewed by Youenn Fablet.
+
+        Use "application/octet-stream" Content-Type for payloads of type ArrayBuffer / ArrayBufferView in Fetch & Beacon.
+        If we don't set a Content-Type header, our underlying network stack is going to add a "application/x-www-form-urlencoded"
+        Content-Type header, which is worse.
+
+        Chrome is already using "application/octet-stream" Content-Type in Beacon, but use no Content-Type in Fetch.
+        The Fetch/Beacon specification says we should have no Content-Type header in this case but this is unfortunately
+        not something we can support at the moment. Using "application/octet-stream" Content-Type for now seems like the
+        lesser evil.
+
+        Test: http/wpt/fetch/fetch-request-arraybuffer-content-type.html
+
+        * Modules/fetch/FetchBody.cpp:
+        (WebCore::FetchBody::extract):
+        * platform/network/HTTPHeaderValues.cpp:
+        (WebCore::HTTPHeaderValues::octetStreamContentType):
+        * platform/network/HTTPHeaderValues.h:
+
 2017-08-15  Robin Morisset  <[email protected]>
 
         Change the order of arguments of JSWithScope::create() for consistency

Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.cpp (220778 => 220779)


--- trunk/Source/WebCore/Modules/fetch/FetchBody.cpp	2017-08-16 01:10:01 UTC (rev 220778)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.cpp	2017-08-16 01:23:50 UTC (rev 220779)
@@ -62,10 +62,16 @@
 
     if (WTF::holds_alternative<RefPtr<ArrayBuffer>>(value)) {
         Ref<const ArrayBuffer> buffer = WTF::get<RefPtr<ArrayBuffer>>(value).releaseNonNull();
+        // FIXME: We should not set a Content-Type here but we need to do this until all network stacks
+        // support sending no Content-Type header (<dar://problem/33906567).
+        contentType = HTTPHeaderValues::octetStreamContentType();
         return FetchBody(WTFMove(buffer));
     }
     if (WTF::holds_alternative<RefPtr<ArrayBufferView>>(value)) {
         Ref<const ArrayBufferView> buffer = WTF::get<RefPtr<ArrayBufferView>>(value).releaseNonNull();
+        // FIXME: We should not set a Content-Type here but we need to do this until all network stacks
+        // support sending no Content-Type header (<dar://problem/33906567).
+        contentType = HTTPHeaderValues::octetStreamContentType();
         return FetchBody(WTFMove(buffer));
     }
 

Modified: trunk/Source/WebCore/platform/network/HTTPHeaderValues.cpp (220778 => 220779)


--- trunk/Source/WebCore/platform/network/HTTPHeaderValues.cpp	2017-08-16 01:10:01 UTC (rev 220778)
+++ trunk/Source/WebCore/platform/network/HTTPHeaderValues.cpp	2017-08-16 01:23:50 UTC (rev 220779)
@@ -44,6 +44,12 @@
     return contentType;
 }
 
+const String& octetStreamContentType()
+{
+    static NeverDestroyed<const String> contentType(MAKE_STATIC_STRING_IMPL("application/octet-stream"));
+    return contentType;
+}
+
 const String& noCache()
 {
     static NeverDestroyed<const String> value(MAKE_STATIC_STRING_IMPL("no-cache"));

Modified: trunk/Source/WebCore/platform/network/HTTPHeaderValues.h (220778 => 220779)


--- trunk/Source/WebCore/platform/network/HTTPHeaderValues.h	2017-08-16 01:10:01 UTC (rev 220778)
+++ trunk/Source/WebCore/platform/network/HTTPHeaderValues.h	2017-08-16 01:23:50 UTC (rev 220779)
@@ -32,6 +32,7 @@
 
 const String& textPlainContentType();
 const String& formURLEncodedContentType();
+const String& octetStreamContentType();
 const String& noCache();
 const String& maxAge0();
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to