lib: use req.socket over deprecated req.connection (#6705)

Signed-off-by: Sebastian Beltran <bjohansebas@gmail.com>
This commit is contained in:
Sebastian Beltran 2025-08-21 10:05:29 -05:00 committed by GitHub
parent d9a62f9833
commit 89f198c6a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View File

@ -282,12 +282,12 @@ req.is = function is(types) {
*/
defineGetter(req, 'protocol', function protocol(){
var proto = this.connection.encrypted
var proto = this.socket.encrypted
? 'https'
: 'http';
var trust = this.app.get('trust proxy fn');
if (!trust(this.connection.remoteAddress, 0)) {
if (!trust(this.socket.remoteAddress, 0)) {
return proto;
}
@ -406,7 +406,7 @@ defineGetter(req, 'host', function host(){
var trust = this.app.get('trust proxy fn');
var val = this.get('X-Forwarded-Host');
if (!val || !trust(this.connection.remoteAddress, 0)) {
if (!val || !trust(this.socket.remoteAddress, 0)) {
val = this.get('Host');
} else if (val.indexOf(',') !== -1) {
// Note: X-Forwarded-Host is normally only ever a

View File

@ -39,7 +39,7 @@ describe('req', function(){
app.enable('trust proxy');
app.use(function(req, res){
req.connection.encrypted = true;
req.socket.encrypted = true;
res.end(req.protocol);
});