Test navigateur isolé du réseau de la machine ; zstd seulement si Node le sait
Le conteneur Playwright partageait le réseau de la machine : quand d'autres conteneurs démarraient, Chromium abandonnait ses chargements (net::ERR_NETWORK_CHANGED). Il a maintenant son réseau, et le vrai serveur tourne à côté de lui. Ce Node (20) n'a pas zstd : le serveur renvoyait 500. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
b037fbd67f
commit
442b3f0a56
+8
-3
@@ -34,12 +34,17 @@ const COMPRESSIBLE = /^(text\/|application\/json|application\/manifest\+json|ima
|
||||
/** Comme Caddy : en dessous, la compression ne fait rien gagner. */
|
||||
const MIN_COMPRESS = 512;
|
||||
|
||||
/** zstd n'existe dans Node qu'à partir de 22.15 (l'image de production a Node 24). */
|
||||
export const HAS_ZSTD = typeof (/** @type {any} */ (zlib)).zstdCompressSync === "function";
|
||||
|
||||
/**
|
||||
* Encodage choisi d'après Accept-Encoding : zstd, sinon gzip, sinon aucun.
|
||||
* Encodage choisi d'après Accept-Encoding : zstd (si ce Node le sait), sinon gzip,
|
||||
* sinon aucun.
|
||||
* @param {string|undefined} header
|
||||
* @param {boolean} [zstd] ce Node sait compresser en zstd
|
||||
* @returns {"zstd"|"gzip"|null}
|
||||
*/
|
||||
export function pickEncoding(header) {
|
||||
export function pickEncoding(header, zstd = HAS_ZSTD) {
|
||||
/** @type {Map<string, number>} */
|
||||
const accepted = new Map();
|
||||
for (const part of (header ?? "").split(",")) {
|
||||
@@ -49,7 +54,7 @@ export function pickEncoding(header) {
|
||||
accepted.set(name, q ? Number(q[1]) : 1);
|
||||
}
|
||||
const ok = (/** @type {string} */ name) => (accepted.get(name) ?? accepted.get("*") ?? 0) > 0;
|
||||
if (ok("zstd")) return "zstd";
|
||||
if (zstd && ok("zstd")) return "zstd";
|
||||
if (ok("gzip")) return "gzip";
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user