Skip to content

Commit

Permalink
fix(send-type): apply custom headers when passed a stream (#198)
Browse files Browse the repository at this point in the history
* 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 <luke.edwards05@gmail.com>

---------

Co-authored-by: Luke Edwards <luke.edwards05@gmail.com>
  • Loading branch information
aral and lukeed authored Dec 4, 2023
1 parent 2ce10df commit 1cf649c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/send-type/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 1cf649c

Please sign in to comment.