req.protocol.js
This file
Path
test/req.protocol.js
77 lines · 1.6 KiB · JavaScript
Last changed by
Added "trust proxy" settingTJ Holowaychukbefore adoption4d87efc
History of this fileTake it
Added `req.protocol()`TJ Holowaychukbefore adoption2ba343d
lines 1–5why, one step back12var express = require('../')3 , request = require('./support/http');45describe('req', function(){Added "trust proxy" settingTJ Holowaychukbefore adoption4d87efc
line 6why, one step back6 describe('.protocol', function(){Added `req.protocol()`TJ Holowaychukbefore adoption2ba343d
lines 7–10why, one step back7 it('should return the protocol string', function(done){8 var app = express();910 app.use(function(req, res){Added "trust proxy" settingTJ Holowaychukbefore adoption4d87efc
line 11why, one step back11 res.end(req.protocol);Added `req.protocol()`TJ Holowaychukbefore adoption2ba343d
lines 12–21why, one step back12 });1314 request(app)15 .get('/')16 .end(function(res){17 res.body.should.equal('http');18 done();19 })20 })21Added "trust proxy" settingTJ Holowaychukbefore adoption4d87efc
line 22why, one step back22 describe('when "trust proxy" is enabled', function(){Added `req.protocol()`TJ Holowaychukbefore adoption2ba343d
lines 23–25why, one step back23 it('should respect X-Forwarded-Proto', function(done){24 var app = express();25Added "trust proxy" settingTJ Holowaychukbefore adoption4d87efc
lines 26–27why, one step back26 app.enable('trust proxy');27Added `req.protocol()`TJ Holowaychukbefore adoption2ba343d
line 28why, one step back28 app.use(function(req, res){Added "trust proxy" settingTJ Holowaychukbefore adoption4d87efc
line 29why, one step back29 res.end(req.protocol);Added `req.protocol()`TJ Holowaychukbefore adoption2ba343d
lines 30–43why, one step back30 });3132 request(app)33 .get('/')34 .set('X-Forwarded-Proto', 'https')35 .end(function(res){36 res.body.should.equal('https');37 done();38 })39 })4041 it('should default to http', function(done){42 var app = express();43Added "trust proxy" settingTJ Holowaychukbefore adoption4d87efc
lines 44–45why, one step back44 app.enable('trust proxy');45Added `req.protocol()`TJ Holowaychukbefore adoption2ba343d
line 46why, one step back46 app.use(function(req, res){Added "trust proxy" settingTJ Holowaychukbefore adoption4d87efc
line 47why, one step back47 res.end(req.protocol);Added `req.protocol()`TJ Holowaychukbefore adoption2ba343d
lines 48–58why, one step back48 });4950 request(app)51 .get('/')52 .end(function(res){53 res.body.should.equal('http');54 done();55 })56 })57 })58Added "trust proxy" settingTJ Holowaychukbefore adoption4d87efc
line 59why, one step back59 describe('when "trust proxy" is disabled', function(){Added `req.protocol()`TJ Holowaychukbefore adoption2ba343d
lines 60–63why, one step back60 it('should ignore X-Forwarded-Proto', function(done){61 var app = express();6263 app.use(function(req, res){Added "trust proxy" settingTJ Holowaychukbefore adoption4d87efc
line 64why, one step back64 res.end(req.protocol);Added `req.protocol()`TJ Holowaychukbefore adoption2ba343d
lines 65–77why, one step back65 });6667 request(app)68 .get('/')69 .set('X-Forwarded-Proto', 'https')70 .end(function(res){71 res.body.should.equal('http');72 done();73 })74 })75 })76 })77})