req.protocol.js
This file
Path
test/req.protocol.js
80 lines · 1.7 KiB · JavaScript
Last changed by
remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
History of this fileTake it
The walk stopped after 200 commits: lines older than 8ab4408 point at it.
add support for multiple X-Forwarded-Proto values. Closes #1646TJ Holowaychukbefore adoption8ab4408
lines 1–2why, one step back12var express = require('../')remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
line 3why, one step back3 , request = require('supertest');add support for multiple X-Forwarded-Proto values. Closes #1646TJ Holowaychukbefore adoption8ab4408
lines 4–34why, one step back45describe('req', function(){6 describe('.protocol', function(){7 it('should return the protocol string', function(done){8 var app = express();910 app.use(function(req, res){11 res.end(req.protocol);12 });1314 request(app)15 .get('/')16 .expect('http', done);17 })1819 describe('when "trust proxy" is enabled', function(){20 it('should respect X-Forwarded-Proto', function(done){21 var app = express();2223 app.enable('trust proxy');2425 app.use(function(req, res){26 res.end(req.protocol);27 });2829 request(app)30 .get('/')31 .set('X-Forwarded-Proto', 'https')32 .expect('https', done);33 })34improve proxy trust with ip address listDouglas Christopher Wilsonbefore adoption566720b
lines 35–49why, one step back35 it('should ignore X-Forwarded-Proto if socket addr not trusted', function(done){36 var app = express();3738 app.set('trust proxy', '10.0.0.1');3940 app.use(function(req, res){41 res.end(req.protocol);42 });4344 request(app)45 .get('/')46 .set('X-Forwarded-Proto', 'https')47 .expect('http', done);48 })49add support for multiple X-Forwarded-Proto values. Closes #1646TJ Holowaychukbefore adoption8ab4408
lines 50–80why, one step back50 it('should default to http', function(done){51 var app = express();5253 app.enable('trust proxy');5455 app.use(function(req, res){56 res.end(req.protocol);57 });5859 request(app)60 .get('/')61 .expect('http', done);62 })63 })6465 describe('when "trust proxy" is disabled', function(){66 it('should ignore X-Forwarded-Proto', function(done){67 var app = express();6869 app.use(function(req, res){70 res.end(req.protocol);71 });7273 request(app)74 .get('/')75 .set('X-Forwarded-Proto', 'https')76 .expect('http', done);77 })78 })79 })80})