mirror of
https://github.com/zebrajr/express.git
synced 2026-01-15 12:15:27 +00:00
78 lines
1.6 KiB
JavaScript
78 lines
1.6 KiB
JavaScript
|
|
var express = require('../')
|
|
, request = require('./support/http');
|
|
|
|
describe('req', function(){
|
|
describe('.protocol', function(){
|
|
it('should return the protocol string', function(done){
|
|
var app = express();
|
|
|
|
app.use(function(req, res){
|
|
res.end(req.protocol);
|
|
});
|
|
|
|
request(app)
|
|
.get('/')
|
|
.end(function(res){
|
|
res.body.should.equal('http');
|
|
done();
|
|
})
|
|
})
|
|
|
|
describe('when "trust proxy" is enabled', function(){
|
|
it('should respect X-Forwarded-Proto', 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')
|
|
.end(function(res){
|
|
res.body.should.equal('https');
|
|
done();
|
|
})
|
|
})
|
|
|
|
it('should default to http', function(done){
|
|
var app = express();
|
|
|
|
app.enable('trust proxy');
|
|
|
|
app.use(function(req, res){
|
|
res.end(req.protocol);
|
|
});
|
|
|
|
request(app)
|
|
.get('/')
|
|
.end(function(res){
|
|
res.body.should.equal('http');
|
|
done();
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('when "trust proxy" is disabled', function(){
|
|
it('should ignore X-Forwarded-Proto', function(done){
|
|
var app = express();
|
|
|
|
app.use(function(req, res){
|
|
res.end(req.protocol);
|
|
});
|
|
|
|
request(app)
|
|
.get('/')
|
|
.set('X-Forwarded-Proto', 'https')
|
|
.end(function(res){
|
|
res.body.should.equal('http');
|
|
done();
|
|
})
|
|
})
|
|
})
|
|
})
|
|
})
|