req.protocol.js
This file
Path
test/req.protocol.js
95 lines · 2.1 KiB · JavaScript
Last changed by
Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
History of this fileTake it
The walk stopped after 200 commits: lines older than 9cf7bba point at it.
deps: connect@2.19.4Douglas Christopher Wilsonbefore adoption9cf7bba
lines 1–34why, one step back12var express = require('../')3 , request = require('supertest');45describe('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 })34Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 35–49why, one step back35 it('should default to the socket addr if X-Forwarded-Proto not present', function(done){36 var app = express();3738 app.enable('trust proxy');3940 app.use(function(req, res){41 req.connection.encrypted = true;42 res.end(req.protocol);43 });4445 request(app)46 .get('/')47 .expect('https', done);48 })49deps: connect@2.19.4Douglas Christopher Wilsonbefore adoption9cf7bba
lines 50–95why, one step back50 it('should ignore X-Forwarded-Proto if socket addr not trusted', function(done){51 var app = express();5253 app.set('trust proxy', '10.0.0.1');5455 app.use(function(req, res){56 res.end(req.protocol);57 });5859 request(app)60 .get('/')61 .set('X-Forwarded-Proto', 'https')62 .expect('http', done);63 })6465 it('should default to http', function(done){66 var app = express();6768 app.enable('trust proxy');6970 app.use(function(req, res){71 res.end(req.protocol);72 });7374 request(app)75 .get('/')76 .expect('http', done);77 })78 })7980 describe('when "trust proxy" is disabled', function(){81 it('should ignore X-Forwarded-Proto', function(done){82 var app = express();8384 app.use(function(req, res){85 res.end(req.protocol);86 });8788 request(app)89 .get('/')90 .set('X-Forwarded-Proto', 'https')91 .expect('http', done);92 })93 })94 })95})