perf: skip parsing of entire "X-Forwarded-Proto" header

This commit is contained in:
Douglas Christopher Wilson 2017-10-09 22:43:23 -04:00
parent b7817ab1b0
commit b97faff6e2
2 changed files with 7 additions and 2 deletions

View File

@ -2,6 +2,7 @@ unreleased
==========
* Fix `TypeError` in `res.send` when given `Buffer` and `ETag` header set
* perf: skip parsing of entire `X-Forwarded-Proto` header
4.16.1 / 2017-09-29
===================

View File

@ -315,8 +315,12 @@ defineGetter(req, 'protocol', function protocol(){
// Note: X-Forwarded-Proto is normally only ever a
// single value, but this is to be safe.
proto = this.get('X-Forwarded-Proto') || proto;
return proto.split(/\s*,\s*/)[0];
var header = this.get('X-Forwarded-Proto') || proto
var index = header.indexOf(',')
return index !== -1
? header.substring(0, index).trim()
: header.trim()
});
/**