writeHead() doesn't necessarily have to be called with an array of headers, write()
can also send headers if necessary.
If you want to access headers (or set them), you can use this:
res.writeHead = function() {
// To set:
this.setHeader('your-header', 'your-header-value');
// To read:
console.log('Content-type:', this.getHeader('content-type'));
// Call the original method !!! see text
oldwriteHead.apply(this, arguments);
};
I'm using apply()
to pass all the arguments to the old method, because writeHead()
can actually have 3 arguments, while your code only assumed there were two.