WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
bug-161228-20160826093228.patch (text/plain), 12.96 KB, created by
youenn fablet
on 2016-08-26 00:34:32 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
youenn fablet
Created:
2016-08-26 00:34:32 PDT
Size:
12.96 KB
patch
obsolete
>Subversion Revision: 204958 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 76763044eb58b19604b7b67be3229381e0a2e630..cb82e07e1b03e33a72f8d6bd4f53527e9b9a4478 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,31 @@ >+2016-08-26 Youenn Fablet <youenn@apple.com> >+ >+ [Fetch API] Blob type should be set from Response/Request contentType header >+ https://bugs.webkit.org/show_bug.cgi?id=161228 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Covered by updated tests. >+ >+ Renaming FetchBody::m_mimeType to m_contentType since that better relates to Content-Type header. >+ Updated FetchRequest and FetchResponse to set m_contentType according request/response headers. >+ Handled the case of a Request created from JS, a Response created from JS and a Response created internally to >+ be used as resolve value in the fetch promise. >+ >+ * Modules/fetch/FetchBody.cpp: >+ (WebCore::FetchBody::FetchBody): Renamed m_mimeType to m_contentType. >+ (WebCore::FetchBody::blob): Ditto. >+ * Modules/fetch/FetchBody.h: Ditto. >+ (WebCore::FetchBody::setContentType): >+ (WebCore::FetchBody::contentType): >+ (WebCore::FetchBody::setMimeType): Deleted. >+ (WebCore::FetchBody::mimeType): Deleted. >+ * Modules/fetch/FetchRequest.cpp: >+ (WebCore::FetchRequest::setBody): set FetchBody::m_contentType according HTTP headers. >+ * Modules/fetch/FetchResponse.cpp: >+ (WebCore::FetchResponse::initializeWith): Ditto. >+ (WebCore::FetchResponse::BodyLoader::didReceiveResponse): Ditto. >+ > 2016-08-24 Frederic Wang <fwang@igalia.com> > > Do not store layout parameters on the RenderMathMLRoot class >diff --git a/Source/WebCore/Modules/fetch/FetchBody.cpp b/Source/WebCore/Modules/fetch/FetchBody.cpp >index 1b8b14af86b4d6def4f8b65ecb4fa7e50192e82b..ce83d874d9bc26e7c339634dafdd42c6b889123c 100644 >--- a/Source/WebCore/Modules/fetch/FetchBody.cpp >+++ b/Source/WebCore/Modules/fetch/FetchBody.cpp >@@ -46,14 +46,14 @@ namespace WebCore { > > FetchBody::FetchBody(Ref<Blob>&& blob) > : m_type(Type::Blob) >- , m_mimeType(blob->type()) >+ , m_contentType(blob->type()) > , m_blob(WTFMove(blob)) > { > } > > FetchBody::FetchBody(Ref<DOMFormData>&& formData) > : m_type(Type::FormData) >- , m_mimeType(ASCIILiteral("multipart/form-data")) >+ , m_contentType(ASCIILiteral("multipart/form-data")) > , m_formData(WTFMove(formData)) > { > // FIXME: Handle the boundary parameter of multipart/form-data MIME type. >@@ -61,7 +61,7 @@ FetchBody::FetchBody(Ref<DOMFormData>&& formData) > > FetchBody::FetchBody(String&& text) > : m_type(Type::Text) >- , m_mimeType(ASCIILiteral("text/plain;charset=UTF-8")) >+ , m_contentType(ASCIILiteral("text/plain;charset=UTF-8")) > , m_text(WTFMove(text)) > { > } >@@ -99,7 +99,7 @@ void FetchBody::blob(FetchBodyOwner& owner, DeferredWrapper&& promise) > { > ASSERT(m_type != Type::None); > m_consumer.setType(FetchBodyConsumer::Type::Blob); >- m_consumer.setContentType(Blob::normalizedContentType(extractMIMETypeFromMediaType(m_mimeType))); >+ m_consumer.setContentType(Blob::normalizedContentType(extractMIMETypeFromMediaType(m_contentType))); > consume(owner, WTFMove(promise)); > } > >diff --git a/Source/WebCore/Modules/fetch/FetchBody.h b/Source/WebCore/Modules/fetch/FetchBody.h >index 4cab3916da70ee0627f4ee3a8818e2e0fad72b52..a8f0120e8ed7330d7a1eae10c1d702854287593a 100644 >--- a/Source/WebCore/Modules/fetch/FetchBody.h >+++ b/Source/WebCore/Modules/fetch/FetchBody.h >@@ -62,8 +62,8 @@ public: > > bool isEmpty() const { return m_type == Type::None; } > >- void setMimeType(const String& mimeType) { m_mimeType = mimeType; } >- String mimeType() const { return m_mimeType; } >+ void setContentType(const String& contentType) { m_contentType = contentType; } >+ String contentType() const { return m_contentType; } > > static FetchBody extract(JSC::ExecState&, JSC::JSValue); > static FetchBody extractFromBody(FetchBody*); >@@ -96,7 +96,7 @@ private: > void consumeBlob(FetchBodyOwner&, DeferredWrapper&&); > > Type m_type { Type::None }; >- String m_mimeType; >+ String m_contentType; > > // FIXME: Add support for BufferSource and URLSearchParams. > RefPtr<Blob> m_blob; >diff --git a/Source/WebCore/Modules/fetch/FetchRequest.cpp b/Source/WebCore/Modules/fetch/FetchRequest.cpp >index 987f97edc5bf976d7230ddd794eeacf37867d50e..775455a3b41d8fd476b81039ac172405633dd33d 100644 >--- a/Source/WebCore/Modules/fetch/FetchRequest.cpp >+++ b/Source/WebCore/Modules/fetch/FetchRequest.cpp >@@ -269,11 +269,11 @@ void FetchRequest::setBody(JSC::ExecState& execState, JSC::JSValue body, FetchRe > } > > String type = m_headers->fastGet(HTTPHeaderName::ContentType); >- if (!body.isUndefined() && type.isEmpty() && !m_body.mimeType().isEmpty()) { >- type = m_body.mimeType(); >- m_headers->fastSet(HTTPHeaderName::ContentType, type); >- } >- m_body.setMimeType(type); >+ if (!type.isEmpty()) >+ m_body.setContentType(type); >+ else if (!body.isUndefined() && !m_body.contentType().isEmpty()) >+ m_headers->fastSet(HTTPHeaderName::ContentType, m_body.contentType()); >+ > if (!validateBodyAndMethod(m_body, m_internalRequest)) > ec = TypeError; > } >diff --git a/Source/WebCore/Modules/fetch/FetchResponse.cpp b/Source/WebCore/Modules/fetch/FetchResponse.cpp >index 82b4a54ee1ddad3baa4379845005fcd0e3f14a1b..1d228f2ba9d565e88c7d592103af6afee4e471a2 100644 >--- a/Source/WebCore/Modules/fetch/FetchResponse.cpp >+++ b/Source/WebCore/Modules/fetch/FetchResponse.cpp >@@ -83,8 +83,12 @@ void FetchResponse::setStatus(int status, const String& statusText, ExceptionCod > void FetchResponse::initializeWith(JSC::ExecState& execState, JSC::JSValue body) > { > m_body = FetchBody::extract(execState, body); >- if (m_headers->fastGet(HTTPHeaderName::ContentType).isEmpty() && !m_body.mimeType().isEmpty()) >- m_headers->fastSet(HTTPHeaderName::ContentType, m_body.mimeType()); >+ String contentType = m_headers->fastGet(HTTPHeaderName::ContentType); >+ if (!contentType.isEmpty()) { >+ if (!m_body.contentType().isEmpty()) >+ m_headers->fastSet(HTTPHeaderName::ContentType, m_body.contentType()); >+ } else >+ m_body.setContentType(contentType); > } > > FetchResponse::FetchResponse(ScriptExecutionContext& context, FetchBody&& body, Ref<FetchHeaders>&& headers, ResourceResponse&& response) >@@ -176,6 +180,7 @@ void FetchResponse::BodyLoader::didReceiveResponse(const ResourceResponse& resou > > m_response.m_response = resourceResponse; > m_response.m_headers->filterAndFill(resourceResponse.httpHeaderFields(), FetchHeaders::Guard::Response); >+ m_response.m_body.setContentType(m_response.m_headers->fastGet(HTTPHeaderName::ContentType)); > > std::exchange(m_promise, Nullopt)->resolve(m_response); > } >diff --git a/LayoutTests/imported/w3c/ChangeLog b/LayoutTests/imported/w3c/ChangeLog >index 4a35b682ecc79863c476fead3ffad0a72ddd73ee..b92c998aecc6adc289ea30fa76bcc9c8c5cd7326 100644 >--- a/LayoutTests/imported/w3c/ChangeLog >+++ b/LayoutTests/imported/w3c/ChangeLog >@@ -1,3 +1,14 @@ >+2016-08-26 Youenn Fablet <youenn@apple.com> >+ >+ [Fetch API] Blob type should be set from Response/Request contentType header >+ https://bugs.webkit.org/show_bug.cgi?id=161228 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * web-platform-tests/fetch/api/request/request-consume.html: >+ * web-platform-tests/fetch/api/response/response-consume-expected.txt: >+ * web-platform-tests/fetch/api/response/response-consume.html: >+ > 2016-08-24 Alex Christensen <achristensen@webkit.org> > > Import w3c URL tests >diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume.html b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume.html >index 292e08c63eeeb551822958b48a1ddea549a27446..16876e5a6033bfa7cf89ed1de2ca20f61596cbc7 100644 >--- a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume.html >+++ b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume.html >@@ -19,8 +19,11 @@ > }); > } > >- function checkBodyBlob(request, expectedBody) { >+ function checkBodyBlob(request, expectedBody, checkContentType) { > return request.blob().then(function(bodyAsBlob) { >+ if (checkContentType) >+ assert_equals(bodyAsBlob.type, "text/plain", "Blob body type should be computed from the request Content-Type"); >+ > var promise = new Promise(function (resolve, reject) { > var reader = new FileReader(); > reader.onload = function(evt) { >@@ -62,7 +65,7 @@ > > function checkRequestBody(body, bodyType, checkFunction) { > promise_test(function(test) { >- var request = new Request("", {"method": "POST", "body": body }); >+ var request = new Request("", {"method": "POST", "body": body, "headers": [["Content-Type", "text/PLAIN"]] }); > assert_false(request.bodyUsed, "bodyUsed is false at init"); > return checkFunction(request, body); > }, "Consume request's body as " + bodyType); >@@ -74,7 +77,7 @@ > var blob = new Blob([textData], { "type" : "text/plain" }); > > checkRequestBody(textData, "text", checkBodyText); >- checkRequestBody(textData, "blob", checkBodyBlob); >+ checkRequestBody(textData, "blob", function(request, body) { checkBodyBlob(request, body, true); }); > checkRequestBody(textData, "arrayBuffer", checkBodyArrayBuffer); > checkRequestBody(textData, "json", checkBodyJSON); > checkRequestBody(formData, "formData", checkBodyFormData); >diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-expected.txt >index 416a392ce6ad6cab68e271dd04a19a2ee50203ee..f1f0f00fdce8f9c4a45d40c5eea3827aa1d46478 100644 >--- a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-expected.txt >+++ b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-expected.txt >@@ -12,4 +12,7 @@ PASS Consume stream response's body as blob > PASS Consume stream response's body as text > PASS Consume stream response's body as json > PASS Consume stream response's body as arrayBuffer >+PASS Consume fetched response's body as blob >+PASS Consume fetched response's body as text >+PASS Consume fetched response's body as arrayBuffer > >diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume.html b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume.html >index 99410cd448ab8bd64790187004efd34b1c99ab49..56e234248c386fb25477f3988633ca7de91aff7b 100644 >--- a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume.html >+++ b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume.html >@@ -19,8 +19,11 @@ > }); > } > >- function checkBodyBlob(response, expectedBody) { >+ function checkBodyBlob(response, expectedBody, checkContentType) { > return response.blob().then(function(bodyAsBlob) { >+ if (checkContentType) >+ assert_equals(bodyAsBlob.type, "text/plain", "Blob body type should be computed from the response Content-Type"); >+ > var promise = new Promise( function (resolve, reject) { > var reader = new FileReader(); > reader.onload = function(evt) { >@@ -62,7 +65,7 @@ > > function checkResponseBody(body, bodyType, checkFunction) { > promise_test(function(test) { >- var response = new Response(body); >+ var response = new Response(body, { "headers": [["Content-Type", "text/PLAIN"]] }); > assert_false(response.bodyUsed, "bodyUsed is false at init"); > return checkFunction(response, body); > }, "Consume response's body as " + bodyType); >@@ -74,7 +77,7 @@ > var blob = new Blob([textData], { "type" : "text/plain" }); > > checkResponseBody(textData, "text", checkBodyText); >- checkResponseBody(textData, "blob", checkBodyBlob); >+ checkResponseBody(textData, "blob", function(response, body) { checkBodyBlob(response, body, true); }); > checkResponseBody(textData, "arrayBuffer", checkBodyArrayBuffer); > checkResponseBody(textData, "json", checkBodyJSON); > checkResponseBody(formData, "formData", checkBodyFormData); >@@ -111,6 +114,18 @@ > checkReadableStreamResponseBody(textData, "json", checkBodyJSON); > checkReadableStreamResponseBody(textData, "arrayBuffer", checkBodyArrayBuffer); > >+ function checkFetchedResponseBody(bodyType, checkFunction) { >+ return promise_test(function(test) { >+ return fetch("../resources/top.txt").then(function(response) { >+ assert_false(response.bodyUsed, "bodyUsed is false at init"); >+ return checkFunction(response, "top"); >+ }); >+ }, "Consume fetched response's body as " + bodyType); >+ } >+ checkFetchedResponseBody("blob", checkBodyBlob); >+ checkFetchedResponseBody("text", checkBodyText); >+ checkFetchedResponseBody("arrayBuffer", checkBodyArrayBuffer); >+ > </script> > </body> > </html>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
buildbot
:
commit-queue-
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 161228
:
287076
|
287080
|
287093
|
287200