mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 00:19:48 +01:00
lib: use req.socket over deprecated req.connection (#6705)
Signed-off-by: Sebastian Beltran <bjohansebas@gmail.com>
This commit is contained in:
parent
d9a62f9833
commit
89f198c6a5
|
|
@ -282,12 +282,12 @@ req.is = function is(types) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defineGetter(req, 'protocol', function protocol(){
|
defineGetter(req, 'protocol', function protocol(){
|
||||||
var proto = this.connection.encrypted
|
var proto = this.socket.encrypted
|
||||||
? 'https'
|
? 'https'
|
||||||
: 'http';
|
: 'http';
|
||||||
var trust = this.app.get('trust proxy fn');
|
var trust = this.app.get('trust proxy fn');
|
||||||
|
|
||||||
if (!trust(this.connection.remoteAddress, 0)) {
|
if (!trust(this.socket.remoteAddress, 0)) {
|
||||||
return proto;
|
return proto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -406,7 +406,7 @@ defineGetter(req, 'host', function host(){
|
||||||
var trust = this.app.get('trust proxy fn');
|
var trust = this.app.get('trust proxy fn');
|
||||||
var val = this.get('X-Forwarded-Host');
|
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');
|
val = this.get('Host');
|
||||||
} else if (val.indexOf(',') !== -1) {
|
} else if (val.indexOf(',') !== -1) {
|
||||||
// Note: X-Forwarded-Host is normally only ever a
|
// Note: X-Forwarded-Host is normally only ever a
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ describe('req', function(){
|
||||||
app.enable('trust proxy');
|
app.enable('trust proxy');
|
||||||
|
|
||||||
app.use(function(req, res){
|
app.use(function(req, res){
|
||||||
req.connection.encrypted = true;
|
req.socket.encrypted = true;
|
||||||
res.end(req.protocol);
|
res.end(req.protocol);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user