Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ defineGetter(req, 'protocol', function protocol(){
var header = this.get('X-Forwarded-Proto') || proto
var index = header.indexOf(',')

return index !== -1
return (index !== -1
? header.substring(0, index).trim()
: header.trim()
: header.trim()).toLowerCase()
});

/**
Expand Down
30 changes: 30 additions & 0 deletions test/req.protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,36 @@ describe('req', function(){
.expect('https', done);
})

it('should normalize X-Forwarded-Proto casing', function(done){
var app = express();

app.enable('trust proxy');

app.use(function(req, res){
res.end(req.protocol);
});

request(app)
.get('/')
.set('X-Forwarded-Proto', 'HTTPS')
.expect('https', done);
})

it('should report secure for uppercase X-Forwarded-Proto https', function(done){
var app = express();

app.enable('trust proxy');

app.use(function(req, res){
res.end(String(req.secure));
});

request(app)
.get('/')
.set('X-Forwarded-Proto', 'HTTPS')
.expect('true', done);
})

it('should default to the socket addr if X-Forwarded-Proto not present', function(done){
var app = express();

Expand Down