From 1cf649c5d6e3924a41a42097156145b0daafc957 Mon Sep 17 00:00:00 2001 From: Aral Balkan Date: Mon, 4 Dec 2023 16:13:52 +0000 Subject: [PATCH] fix(send-type): apply custom headers when passed a stream (#198) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixes #197: apply custom headers when passed a stream * Use setHeader instead of writeHead to fix Chrome issue * Use for…in loop as suggested by Luke I don’t have a preference either way as long as all the headers are sent ;) Co-authored-by: Luke Edwards --------- Co-authored-by: Luke Edwards --- packages/send-type/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/send-type/index.js b/packages/send-type/index.js index 07ed619..83cecaa 100644 --- a/packages/send-type/index.js +++ b/packages/send-type/index.js @@ -12,7 +12,10 @@ module.exports = function (res, code=200, data='', headers={}) { let type = obj[TYPE] || res.getHeader(TYPE); if (!!data && typeof data.pipe === 'function') { - res.setHeader(TYPE, type || OSTREAM); + obj[TYPE] = type || OSTREAM; + for (k in obj) { + res.setHeader(k, obj[k]); + } return data.pipe(res); }