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:
parent
419fe2e6b4
commit
0cbaeca026
2 changed files with 21 additions and 15 deletions
|
@ -148,6 +148,7 @@
|
||||||
async function mainFetch(req, recursive, terminator) {
|
async function mainFetch(req, recursive, terminator) {
|
||||||
/** @type {ReadableStream<Uint8Array> | Uint8Array | null} */
|
/** @type {ReadableStream<Uint8Array> | Uint8Array | null} */
|
||||||
let reqBody = null;
|
let reqBody = null;
|
||||||
|
|
||||||
if (req.body !== null) {
|
if (req.body !== null) {
|
||||||
if (req.body.streamOrStatic instanceof ReadableStream) {
|
if (req.body.streamOrStatic instanceof ReadableStream) {
|
||||||
if (req.body.length === null) {
|
if (req.body.length === null) {
|
||||||
|
@ -269,9 +270,14 @@
|
||||||
if (nullBodyStatus(response.status)) {
|
if (nullBodyStatus(response.status)) {
|
||||||
core.close(resp.responseRid);
|
core.close(resp.responseRid);
|
||||||
} else {
|
} else {
|
||||||
response.body = new InnerBody(
|
if (req.method === "HEAD" || req.method === "OPTIONS") {
|
||||||
createResponseBodyStream(resp.responseRid, terminator),
|
response.body = null;
|
||||||
);
|
core.close(resp.responseRid);
|
||||||
|
} else {
|
||||||
|
response.body = new InnerBody(
|
||||||
|
createResponseBodyStream(resp.responseRid, terminator),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recursive) return response;
|
if (recursive) return response;
|
||||||
|
@ -289,8 +295,9 @@
|
||||||
* @returns {Promise<InnerResponse>}
|
* @returns {Promise<InnerResponse>}
|
||||||
*/
|
*/
|
||||||
function httpRedirectFetch(request, response, terminator) {
|
function httpRedirectFetch(request, response, terminator) {
|
||||||
const locationHeaders = response.headerList
|
const locationHeaders = response.headerList.filter(
|
||||||
.filter((entry) => entry[0] === "location");
|
(entry) => entry[0] === "location",
|
||||||
|
);
|
||||||
if (locationHeaders.length === 0) {
|
if (locationHeaders.length === 0) {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
@ -309,7 +316,8 @@
|
||||||
}
|
}
|
||||||
request.redirectCount++;
|
request.redirectCount++;
|
||||||
if (
|
if (
|
||||||
response.status !== 303 && request.body !== null &&
|
response.status !== 303 &&
|
||||||
|
request.body !== null &&
|
||||||
request.body.source === null
|
request.body.source === null
|
||||||
) {
|
) {
|
||||||
return networkError(
|
return networkError(
|
||||||
|
@ -320,7 +328,8 @@
|
||||||
((response.status === 301 || response.status === 302) &&
|
((response.status === 301 || response.status === 302) &&
|
||||||
request.method === "POST") ||
|
request.method === "POST") ||
|
||||||
(response.status === 303 &&
|
(response.status === 303 &&
|
||||||
(request.method !== "GET" && request.method !== "HEAD"))
|
request.method !== "GET" &&
|
||||||
|
request.method !== "HEAD")
|
||||||
) {
|
) {
|
||||||
request.method = "GET";
|
request.method = "GET";
|
||||||
request.body = null;
|
request.body = null;
|
||||||
|
|
|
@ -234,9 +234,7 @@
|
||||||
},
|
},
|
||||||
"hr-time": {
|
"hr-time": {
|
||||||
"monotonic-clock.any.html": true,
|
"monotonic-clock.any.html": true,
|
||||||
"basic.any.html": [
|
"basic.any.html": ["Performance interface extends EventTarget."],
|
||||||
"Performance interface extends EventTarget."
|
|
||||||
],
|
|
||||||
"idlharness.any.html": [
|
"idlharness.any.html": [
|
||||||
"Performance interface: existence and properties of interface object",
|
"Performance interface: existence and properties of interface object",
|
||||||
"Performance interface: existence and properties of interface prototype 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: performance must inherit property \"toJSON()\" with the proper type",
|
||||||
"Performance interface: default toJSON operation on performance",
|
"Performance interface: default toJSON operation on performance",
|
||||||
"Window interface: attribute performance"
|
"Window interface: attribute performance"
|
||||||
]
|
],
|
||||||
|
"window-worker-timeOrigin.window.html": false
|
||||||
},
|
},
|
||||||
"streams": {
|
"streams": {
|
||||||
"idlharness.any.html": [
|
"idlharness.any.html": [
|
||||||
|
@ -765,9 +764,7 @@
|
||||||
"response-url.sub.any.html": true,
|
"response-url.sub.any.html": true,
|
||||||
"scheme-about.any.html": true,
|
"scheme-about.any.html": true,
|
||||||
"scheme-blob.sub.any.html": true,
|
"scheme-blob.sub.any.html": true,
|
||||||
"scheme-data.any.html": [
|
"scheme-data.any.html": true,
|
||||||
"Fetching [HEAD] data:,response%27s%20body is OK"
|
|
||||||
],
|
|
||||||
"scheme-others.sub.any.html": true,
|
"scheme-others.sub.any.html": true,
|
||||||
"stream-response.any.html": true,
|
"stream-response.any.html": true,
|
||||||
"stream-safe-creation.any.html": [
|
"stream-safe-creation.any.html": [
|
||||||
|
@ -1027,4 +1024,4 @@
|
||||||
"set.any.html": true
|
"set.any.html": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue