From ed53ea20611095a763702ea69e6d30a82157b6d8 Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Thu, 19 Dec 2024 22:33:01 +0100 Subject: [PATCH] fix: fix the cache mod not working in Bun, because of extraneous res.writeHead operation --- src/index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 30cdf56..dfa8a4c 100644 --- a/src/index.js +++ b/src/index.js @@ -77,11 +77,13 @@ module.exports = function (req, res, logFacilities, config, next) { res.writeHead = function (statusCode, statusCodeDescription, headers) { const properHeaders = headers ? headers : statusCodeDescription; - Object.keys(properHeaders).forEach((key) => { - writtenHeaders[key.toLowerCase()] = properHeaders[key]; - }); - writtenStatusCode = statusCode; - res.setHeader("X-SVRJS-Cache", "MISS"); + if (typeof properHeaders === "object" && properHeaders !== null) { + Object.keys(properHeaders).forEach((key) => { + writtenHeaders[key.toLowerCase()] = properHeaders[key]; + }); + writtenStatusCode = statusCode; + res.setHeader("X-SVRJS-Cache", "MISS"); + } if (headers) { originalWriteHead( writtenStatusCode,