From 6f585dac33489efd593cfbaf7927e9a752b9217d Mon Sep 17 00:00:00 2001 From: Blink WPT Bot Date: Thu, 5 Aug 2021 21:11:08 +0000 Subject: [PATCH] Bug 1723518 [wpt PR 29866] - HTTP cache: Fix http-cache.js Header Fields Too Large., a=testonly Automatic update from web-platform-tests HTTP cache: Fix http-cache.js Header Fields Too Large. (#29866) Due to a bug in http-cache.js, sending multiple requests can cause: ``` 431 Request Header Fields Too Large ``` That's because the base64 encoded list of requests was added to ... the list of requests ... iteratively. So the size of request was growing quadratically relatively to the number of requests. This has been fixed by copying the list of request instead of taking a new reference. Explanation: The code was executing iteratively: - config = requests[idx]; - fetchInit(requests, config); - init.headers = config['request_headers']; - init.headers.push(['Test-Request', btoa(JSON.stringify(requests))]); which equivalent to: - requests[idx].requests_headers.push( ['Test-Request'], btoa(JSON.stringify(requests))]), So we stringify "requests" and append the result into "requests" iteratively => Boom. Bug: 1221529 Change-Id: Ib9468d95daca2987dd7c391551387f3107dcb1bc Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3063967 Commit-Queue: Arthur Sonzogni Reviewed-by: Maksim Orlovich Cr-Commit-Position: refs/heads/master@{#908039} Co-authored-by: Arthur Sonzogni -- wpt-commits: 34e20f134472dc923d02206fe13819681ca63155 wpt-pr: 29866 --- testing/web-platform/tests/fetch/http-cache/http-cache.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/testing/web-platform/tests/fetch/http-cache/http-cache.js b/testing/web-platform/tests/fetch/http-cache/http-cache.js index a47081b9aff4..19f1ca9b2bcc 100644 --- a/testing/web-platform/tests/fetch/http-cache/http-cache.js +++ b/testing/web-platform/tests/fetch/http-cache/http-cache.js @@ -122,7 +122,9 @@ function fetchInit (requests, config) { 'headers': [] } if ('request_method' in config) init.method = config['request_method'] - if ('request_headers' in config) init.headers = config['request_headers'] + // Note: init.headers must be a copy of config['request_headers'] array, + // because new elements are added later. + if ('request_headers' in config) init.headers = [...config['request_headers']]; if ('name' in config) init.headers.push(['Test-Name', config.name]) if ('request_body' in config) init.body = config['request_body'] if ('mode' in config) init.mode = config['mode'] -- 2.11.4.GIT