Skip to content

Instantly share code, notes, and snippets.

@Epskampie
Last active August 29, 2015 14:00
Show Gist options
  • Save Epskampie/11281368 to your computer and use it in GitHub Desktop.
Save Epskampie/11281368 to your computer and use it in GitHub Desktop.
nodejs uppercase headers hack
var http = require('http');
var automaticHeaders = {
connection: true,
'content-length': true,
'transfer-encoding': true,
date: true
};
http.OutgoingMessage.prototype.setHeader = function(name, value) {
if (arguments.length < 2) {
throw new Error('`name` and `value` are required for setHeader().');
}
if (this._header) {
throw new Error('Can\'t set headers after they are sent.');
}
// NO LOWER CASE
var key = name//.toLowerCase();
this._headers = this._headers || {};
this._headerNames = this._headerNames || {};
this._headers[key] = value;
this._headerNames[key] = name;
if (automaticHeaders[key]) {
this._removedHeader[key] = false;
}
};
@danschumann
Copy link

oh yea.. i suppose automaticHeaders is defined in express somewhere and I didn't transfer that over in my implementation.. whoops!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment