1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-18 03:44:05 -05:00

fix: fetch with method HEAD should not have body (#11003)

This commit is contained in:
Yasser A.Idrissi 2021-06-18 10:14:14 +01:00 committed by GitHub
parent 419fe2e6b4
commit 0cbaeca026
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 15 deletions

View file

@ -148,6 +148,7 @@
async function mainFetch(req, recursive, terminator) {
/** @type {ReadableStream<Uint8Array> | Uint8Array | null} */
let reqBody = null;
if (req.body !== null) {
if (req.body.streamOrStatic instanceof ReadableStream) {
if (req.body.length === null) {
@ -269,9 +270,14 @@
if (nullBodyStatus(response.status)) {
core.close(resp.responseRid);
} else {
response.body = new InnerBody(
createResponseBodyStream(resp.responseRid, terminator),
);
if (req.method === "HEAD" || req.method === "OPTIONS") {
response.body = null;
core.close(resp.responseRid);
} else {
response.body = new InnerBody(
createResponseBodyStream(resp.responseRid, terminator),
);
}
}
if (recursive) return response;
@ -289,8 +295,9 @@
* @returns {Promise<InnerResponse>}
*/
function httpRedirectFetch(request, response, terminator) {
const locationHeaders = response.headerList
.filter((entry) => entry[0] === "location");
const locationHeaders = response.headerList.filter(
(entry) => entry[0] === "location",
);
if (locationHeaders.length === 0) {
return response;
}
@ -309,7 +316,8 @@
}
request.redirectCount++;
if (
response.status !== 303 && request.body !== null &&
response.status !== 303 &&
request.body !== null &&
request.body.source === null
) {
return networkError(
@ -320,7 +328,8 @@
((response.status === 301 || response.status === 302) &&
request.method === "POST") ||
(response.status === 303 &&
(request.method !== "GET" && request.method !== "HEAD"))
request.method !== "GET" &&
request.method !== "HEAD")
) {
request.method = "GET";
request.body = null;

View file

@ -234,9 +234,7 @@
},
"hr-time": {
"monotonic-clock.any.html": true,
"basic.any.html": [
"Performance interface extends EventTarget."
],
"basic.any.html": ["Performance interface extends EventTarget."],
"idlharness.any.html": [
"Performance interface: existence and properties of interface object",
"Performance interface: existence and properties of interface prototype object",
@ -248,7 +246,8 @@
"Performance interface: performance must inherit property \"toJSON()\" with the proper type",
"Performance interface: default toJSON operation on performance",
"Window interface: attribute performance"
]
],
"window-worker-timeOrigin.window.html": false
},
"streams": {
"idlharness.any.html": [
@ -765,9 +764,7 @@
"response-url.sub.any.html": true,
"scheme-about.any.html": true,
"scheme-blob.sub.any.html": true,
"scheme-data.any.html": [
"Fetching [HEAD] data:,response%27s%20body is OK"
],
"scheme-data.any.html": true,
"scheme-others.sub.any.html": true,
"stream-response.any.html": true,
"stream-safe-creation.any.html": [