Created
May 7, 2015 12:31
-
-
Save krazylearner/191a6d0368b9e622873b to your computer and use it in GitHub Desktop.
Normalizes HTTP header names according to RFC 2616.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A map of HTTP header names with irregular case. | |
* IrregularHeaderNames.js | |
*/ | |
module.exports = [ | |
'Content-ID', | |
'Content-MD5', | |
'DNT', | |
'ETag', | |
'P3P', | |
'TE', | |
'WWW-Authenticate', | |
'X-ATT-DeviceId', | |
'X-UA-Compatible', | |
'X-WebKit-CSP', | |
'X-XSS-Protection' | |
].reduce(function (map, headerName) { | |
map[headerName.toLowerCase()] = headerName; | |
return map; | |
}, {}); | |
/*************************************************************************/ | |
"use strict"; | |
var IrregularHeaderNames = require("./IrregularHeaderNames"); | |
/** | |
* Normalizes HTTP header names according to RFC 2616. | |
*/ | |
function normalizeHeaderName(headerName) { | |
headerName = headerName.toLowerCase(); | |
if (headerName in IrregularHeaderNames) { | |
return IrregularHeaderNames[headerName]; | |
}return headerName.replace(/(^|-)([a-z])/g, function (match, dash, letter) { | |
return dash + letter.toUpperCase(); | |
}); | |
} | |
module.exports = normalizeHeaderName; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment