diff --git a/History.md b/History.md index f51da8df..f7313199 100644 --- a/History.md +++ b/History.md @@ -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 =================== diff --git a/lib/request.js b/lib/request.js index 3432e677..8bb86a9a 100644 --- a/lib/request.js +++ b/lib/request.js @@ -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() }); /**