diff --git a/lib/request.js b/lib/request.js index 372a9915e9..476961fae7 100644 --- a/lib/request.js +++ b/lib/request.js @@ -399,17 +399,17 @@ defineGetter(req, 'path', function path() { * address, the "X-Forwarded-Host" header field will * be trusted. * - * @return {String} + * @return {(String|undefined)} * @public */ -defineGetter(req, 'host', function host(){ - var trust = this.app.get('trust proxy fn'); - var val = this.get('X-Forwarded-Host'); +defineGetter(req, 'host', function() { + const trust = this.app.get('trust proxy fn'); + let val = this.get('X-Forwarded-Host'); if (!val || !trust(this.connection.remoteAddress, 0)) { val = this.get('Host'); - } else if (val.indexOf(',') !== -1) { + } else if (val.includes(',')) { // Note: X-Forwarded-Host is normally only ever a // single value, but this is to be safe. val = val.substring(0, val.indexOf(',')).trimRight() @@ -418,6 +418,7 @@ defineGetter(req, 'host', function host(){ return val || undefined; }); + /** * Parse the "Host" header field to a hostname. *