Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Respect Content-Type from internal headers instead of caching it in body
https://bugs.webkit.org/show_bug.cgi?id=220535 Reviewed by Youenn Fablet. Previously, Content-Type is cached as `m_contentType` in FetchBodyOwner. However, as the spec says, Content-Type should be derived from the one in Headers. Thus, we'd like to remove the cached Content-Type and always retrieve it from internal headers instead. * LayoutTests/http/wpt/fetch/fetch-as-blob-expected.txt: Removed. * LayoutTests/http/wpt/fetch/fetch-as-blob-worker-expected.txt: Removed. * LayoutTests/http/wpt/fetch/fetch-as-blob-worker.html: Removed. * LayoutTests/http/wpt/fetch/fetch-as-blob.html: Removed. * LayoutTests/http/wpt/fetch/fetch-as-blob.js: Removed. * LayoutTests/imported/w3c/resources/import-expectations.json: * LayoutTests/imported/w3c/web-platform-tests/fetch/api/body/cloned-any.js: Added. (promise_test.async t): * LayoutTests/imported/w3c/web-platform-tests/fetch/api/body/mime-type.any-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/fetch/api/body/mime-type.any.js: (forEach.bodyContainerCreator.promise_test.async t): (forEach.bodyContainerCreator.assert_equals): (new.Response.new.Blob.string_appeared_here.forEach.bodyContainerCreator.promise_test.async t): (new.Response.new.Blob.string_appeared_here.forEach.bodyContainerCreator.assert_equals): (new.Response.new.Blob): * LayoutTests/imported/w3c/web-platform-tests/fetch/api/body/mime-type.any.worker-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/fetch/api/body/w3c-import.log: * LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/cache-match.https.any-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/cache-match.https.any.serviceworker-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/cache-match.https.any.sharedworker-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/cache-match.https.any.worker-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/serviceworker/cache-match.https-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-match.https-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/worker/cache-match.https-expected.txt: * Source/WebCore/Modules/fetch/FetchBody.cpp: (WebCore::FetchBody::blob): (WebCore::FetchBody::consumeOnceLoadingFinished): * Source/WebCore/Modules/fetch/FetchBody.h: * Source/WebCore/Modules/fetch/FetchBodyConsumer.cpp: (WebCore::resolveWithTypeAndData): (WebCore::FetchBodyConsumer::resolve): (WebCore::FetchBodyConsumer::takeAsBlob): (WebCore::FetchBodyConsumer::clone): * Source/WebCore/Modules/fetch/FetchBodyConsumer.h: (WebCore::FetchBodyConsumer::setContentType): Deleted. * Source/WebCore/Modules/fetch/FetchBodyOwner.cpp: (WebCore::FetchBodyOwner::blob): (WebCore::FetchBodyOwner::cloneBody): (WebCore::FetchBodyOwner::extractBody): (WebCore::FetchBodyOwner::consumeOnceLoadingFinished): (WebCore::FetchBodyOwner::formData): (WebCore::FetchBodyOwner::updateContentType): Deleted. * Source/WebCore/Modules/fetch/FetchBodyOwner.h: (WebCore::FetchBodyOwner::contentType const): * Source/WebCore/Modules/fetch/FetchRequest.cpp: (WebCore::m_signal): (WebCore::FetchRequest::initializeWith): * Source/WebCore/Modules/fetch/FetchResponse.cpp: (WebCore::FetchResponse::create): (WebCore::FetchResponse::clone): (WebCore::FetchResponse::setReceivedInternalResponse): Canonical link: https://commits.webkit.org/264054@main
- Loading branch information
Showing
26 changed files
with
216 additions
and
205 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
LayoutTests/imported/w3c/web-platform-tests/fetch/api/body/cloned-any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Changing the body after it have been passed to Response/Request | ||
// should not change the outcome of the consumed body | ||
|
||
const url = 'http://a'; | ||
const method = 'post'; | ||
|
||
promise_test(async t => { | ||
const body = new FormData(); | ||
body.set('a', '1'); | ||
const res = new Response(body); | ||
const req = new Request(url, { method, body }); | ||
body.set('a', '2'); | ||
assert_true((await res.formData()).get('a') === '1'); | ||
assert_true((await req.formData()).get('a') === '1'); | ||
}, 'FormData is cloned'); | ||
|
||
promise_test(async t => { | ||
const body = new URLSearchParams({a: '1'}); | ||
const res = new Response(body); | ||
const req = new Request(url, { method, body }); | ||
body.set('a', '2'); | ||
assert_true((await res.formData()).get('a') === '1'); | ||
assert_true((await req.formData()).get('a') === '1'); | ||
}, 'URLSearchParams is cloned'); | ||
|
||
promise_test(async t => { | ||
const body = new Uint8Array([97]); // a | ||
const res = new Response(body); | ||
const req = new Request(url, { method, body }); | ||
body[0] = 98; // b | ||
assert_true(await res.text() === 'a'); | ||
assert_true(await req.text() === 'a'); | ||
}, 'TypedArray is cloned'); | ||
|
||
promise_test(async t => { | ||
const body = new Uint8Array([97]); // a | ||
const res = new Response(body.buffer); | ||
const req = new Request(url, { method, body: body.buffer }); | ||
body[0] = 98; // b | ||
assert_true(await res.text() === 'a'); | ||
assert_true(await req.text() === 'a'); | ||
}, 'ArrayBuffer is cloned'); | ||
|
||
promise_test(async t => { | ||
const body = new Blob(['a']); | ||
const res = new Response(body); | ||
const req = new Request(url, { method, body }); | ||
assert_true(await res.blob() !== body); | ||
assert_true(await req.blob() !== body); | ||
}, 'Blob is cloned'); |
26 changes: 20 additions & 6 deletions
26
LayoutTests/imported/w3c/web-platform-tests/fetch/api/body/mime-type.any-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
|
||
FAIL Request: overriding explicit Content-Type assert_equals: expected "test/test" but got "text/plain" | ||
FAIL Response: overriding explicit Content-Type assert_equals: expected "test/test" but got "text/plain" | ||
FAIL Request: removing implicit Content-Type assert_equals: expected "" but got "application/x-www-form-urlencoded;charset=utf-8" | ||
FAIL Response: removing implicit Content-Type assert_equals: expected "" but got "application/x-www-form-urlencoded;charset=utf-8" | ||
FAIL Request: setting missing Content-Type assert_equals: expected "test/test" but got "" | ||
FAIL Response: setting missing Content-Type assert_equals: expected "test/test" but got "" | ||
PASS Request: overriding explicit Content-Type | ||
PASS Response: overriding explicit Content-Type | ||
PASS Request: removing implicit Content-Type | ||
PASS Response: removing implicit Content-Type | ||
PASS Request: setting missing Content-Type | ||
PASS Response: setting missing Content-Type | ||
PASS Request: MIME type for Blob from empty body | ||
PASS Response: MIME type for Blob from empty body | ||
PASS Request: MIME type for Blob from empty body with Content-Type | ||
PASS Response: MIME type for Blob from empty body with Content-Type | ||
PASS Request: MIME type for Blob | ||
PASS Response: MIME type for Blob | ||
PASS Request: MIME type for Blob with non-empty type | ||
PASS Response: MIME type for Blob with non-empty type | ||
PASS Request: Extract a MIME type with clone | ||
FAIL Response: Extract a MIME type with clone assert_equals: expected "text/html" but got "text/plain" | ||
PASS Request: Content-Type in headers wins Blob"s type | ||
PASS Response: Content-Type in headers wins Blob"s type | ||
PASS Request: setting missing Content-Type in headers and it wins Blob"s type | ||
PASS Response: setting missing Content-Type in headers and it wins Blob"s type | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 20 additions & 6 deletions
26
LayoutTests/imported/w3c/web-platform-tests/fetch/api/body/mime-type.any.worker-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
|
||
FAIL Request: overriding explicit Content-Type assert_equals: expected "test/test" but got "text/plain" | ||
FAIL Response: overriding explicit Content-Type assert_equals: expected "test/test" but got "text/plain" | ||
FAIL Request: removing implicit Content-Type assert_equals: expected "" but got "application/x-www-form-urlencoded;charset=utf-8" | ||
FAIL Response: removing implicit Content-Type assert_equals: expected "" but got "application/x-www-form-urlencoded;charset=utf-8" | ||
FAIL Request: setting missing Content-Type assert_equals: expected "test/test" but got "" | ||
FAIL Response: setting missing Content-Type assert_equals: expected "test/test" but got "" | ||
PASS Request: overriding explicit Content-Type | ||
PASS Response: overriding explicit Content-Type | ||
PASS Request: removing implicit Content-Type | ||
PASS Response: removing implicit Content-Type | ||
PASS Request: setting missing Content-Type | ||
PASS Response: setting missing Content-Type | ||
PASS Request: MIME type for Blob from empty body | ||
PASS Response: MIME type for Blob from empty body | ||
PASS Request: MIME type for Blob from empty body with Content-Type | ||
PASS Response: MIME type for Blob from empty body with Content-Type | ||
PASS Request: MIME type for Blob | ||
PASS Response: MIME type for Blob | ||
PASS Request: MIME type for Blob with non-empty type | ||
PASS Response: MIME type for Blob with non-empty type | ||
PASS Request: Extract a MIME type with clone | ||
FAIL Response: Extract a MIME type with clone assert_equals: expected "text/html" but got "text/plain" | ||
PASS Request: Content-Type in headers wins Blob"s type | ||
PASS Response: Content-Type in headers wins Blob"s type | ||
PASS Request: setting missing Content-Type in headers and it wins Blob"s type | ||
PASS Response: setting missing Content-Type in headers and it wins Blob"s type | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.