From 7f0e55c1ef2283b4b69bbf50dd0dd558014e11eb Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 10 Dec 2024 22:15:00 +0100 Subject: [PATCH] Try to fix intermittent failure in `handle reading ranges with missing/invalid "Content-Range" header` unit-test (PR 19114 follow-up) Implements https://github.com/mozilla/pdf.js/pull/19114#discussion_r1873052489, which didn't seem necessary at the time since the unit-tests passed (many times) in PR 19114. --- test/webserver.mjs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/webserver.mjs b/test/webserver.mjs index dd2ae735ecbd1..2f92637ca2651 100644 --- a/test/webserver.mjs +++ b/test/webserver.mjs @@ -189,7 +189,7 @@ class WebServer { if (this.verbose) { console.log(url); } - this.#serveFile(response, localURL, fileSize); + this.#serveFile(response, localURL, url.searchParams, fileSize); } async #serveDirectoryIndex(response, url, localUrl) { @@ -287,7 +287,7 @@ class WebServer { response.end(""); } - #serveFile(response, fileURL, fileSize) { + #serveFile(response, fileURL, searchParams, fileSize) { const stream = fs.createReadStream(fileURL, { flags: "rs" }); stream.on("error", error => { response.writeHead(500); @@ -304,6 +304,12 @@ class WebServer { expireTime.setSeconds(expireTime.getSeconds() + this.cacheExpirationTime); response.setHeader("Expires", expireTime.toUTCString()); } + + // Support test in `test/unit/network_spec.js`. + if (searchParams.has("test-network-break-ranges")) { + // Refer to the comment in `redirectHandler` below. + response.setHeader("Cache-Control", "no-store,max-age=0"); + } response.writeHead(200); stream.pipe(response); }