Skip to content

Commit

Permalink
perf: skip unnecessary parsing of entire header
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Sep 27, 2017
1 parent 5a7d6a1 commit 4c58835
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ unreleased
- perf: unroll the "fast-path" `RegExp`
* deps: vary@~1.1.2
- perf: improve header token parsing speed
* perf: skip unnecessary parsing of entire header

2.3.9 / 2017-05-19
==================
Expand Down
16 changes: 14 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,26 @@ function createQueryGetter (key) {
*/

function createHeaderGetter (str) {
var header = str.toLowerCase()
var name = str.toLowerCase()

return function (req, res) {
// set appropriate Vary header
vary(res, str)

// get header
var header = req.headers[name]

if (!header) {
return undefined
}

// multiple headers get joined with comma by node.js core
return (req.headers[header] || '').split(/ *, */)
var index = header.indexOf(',')

// return first value
return index !== -1
? header.substr(0, index).trim()
: header.trim()
}
}

Expand Down

0 comments on commit 4c58835

Please sign in to comment.