From 84023e2eb88131dcec3c88d7f924ad757a53c969 Mon Sep 17 00:00:00 2001 From: Tau Date: Sat, 7 Sep 2019 17:04:14 -0400 Subject: [PATCH] chunithm.ts: Beat compression m/ware with a wrench Force unconditional compression of responses harder. --- src/chunithm.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/chunithm.ts b/src/chunithm.ts index 8d2bb57..cf04def 100644 --- a/src/chunithm.ts +++ b/src/chunithm.ts @@ -8,7 +8,20 @@ const app = express(); // attempt to inflate whatever response we send to it whether there's a // Transfer-Encoding header or not. -app.use(compression()); +app.use(function(req, res, next) { + // Chunithm client does not follow the HTTP spec: user agents must indicate + // that they are willing to accept a particular Transfer-Encoding for that + // T-E to be used (unless the T-E in question is "chunked" but w/e), and this + // indication is advisory anyway, the server is permitted to ignore it. + // + // Force this header into the request, since it is not present normally. + + req.headers["accept-encoding"] = "deflate"; + + return next(); +}); + +app.use(compression({ threshold: 0 })); app.use(express.json()); // Trace requests and responses