From 0cbaeca026a7d79a57c859e5e395f0d998fab5d1 Mon Sep 17 00:00:00 2001 From: "Yasser A.Idrissi" Date: Fri, 18 Jun 2021 10:14:14 +0100 Subject: [PATCH] fix: fetch with method HEAD should not have body (#11003) --- extensions/fetch/26_fetch.js | 23 ++++++++++++++++------- tools/wpt/expectation.json | 13 +++++-------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/extensions/fetch/26_fetch.js b/extensions/fetch/26_fetch.js index cf336f7a55..d1fd1e9b36 100644 --- a/extensions/fetch/26_fetch.js +++ b/extensions/fetch/26_fetch.js @@ -148,6 +148,7 @@ async function mainFetch(req, recursive, terminator) { /** @type {ReadableStream | 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} */ 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; diff --git a/tools/wpt/expectation.json b/tools/wpt/expectation.json index 54e8fe7d03..0001f92d30 100644 --- a/tools/wpt/expectation.json +++ b/tools/wpt/expectation.json @@ -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": [ @@ -1027,4 +1024,4 @@ "set.any.html": true } } -} \ No newline at end of file +}