From 5c2ca9805d79200970ffa78aaafff4b404ceca31 Mon Sep 17 00:00:00 2001 From: Ayoub-Mabrouk Date: Sun, 3 Nov 2024 21:27:30 +0100 Subject: [PATCH] docs: update JSDoc for req.host getter - Changed the return type annotation to include `undefined`, reflecting the actual return value. - Updated the implementation to use modern JavaScript methods for better readability and performance. - Clarified comments regarding the handling of the X-Forwarded-Host header. --- lib/request.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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. *