summaryrefslogtreecommitdiff
path: root/ext/fetch/23_request.js
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2022-12-06 09:39:04 +0100
committerGitHub <noreply@github.com>2022-12-06 09:39:04 +0100
commit923370f18fc936e782ed9515744e675aebb59750 (patch)
treeb994a4eec4b58485ddd6e21dfd37da9b64f7f9ba /ext/fetch/23_request.js
parent3973ceb634afe7b4f38678efe0394da84d9c60a1 (diff)
fix(ext/fetch): new Request should soft clone (#16869)
Previously the inner request object of the original and the new request were the same, causing the requests to be entangled and mutable changes to one to be visible to the other. This fixes that.
Diffstat (limited to 'ext/fetch/23_request.js')
-rw-r--r--ext/fetch/23_request.js12
1 files changed, 7 insertions, 5 deletions
diff --git a/ext/fetch/23_request.js b/ext/fetch/23_request.js
index 508a29139..c09e3326f 100644
--- a/ext/fetch/23_request.js
+++ b/ext/fetch/23_request.js
@@ -157,14 +157,14 @@
* @param {InnerRequest} request
* @returns {InnerRequest}
*/
- function cloneInnerRequest(request) {
+ function cloneInnerRequest(request, skipBody = false) {
const headerList = ArrayPrototypeMap(
request.headerList,
(x) => [x[0], x[1]],
);
let body = null;
- if (request.body !== null) {
+ if (request.body !== null && !skipBody) {
body = request.body.clone();
}
@@ -315,12 +315,14 @@
if (!ObjectPrototypeIsPrototypeOf(RequestPrototype, input)) {
throw new TypeError("Unreachable");
}
- request = input[_request];
+ const originalReq = input[_request];
+ // fold in of step 12 from below
+ request = cloneInnerRequest(originalReq, true);
+ request.redirectCount = 0; // reset to 0 - cloneInnerRequest copies the value
signal = input[_signal];
}
- // 12.
- // TODO(lucacasonato): create a copy of `request`
+ // 12. is folded into the else statement of step 6 above.
// 22.
if (init.redirect !== undefined) {