Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than d581592 point at it.

3.5.2Douglas Christopher Wilsonbefore adoptiond581592

lines 1–2why, one step back
1
2var express = require('../')

remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3

line 3why, one step back
3 , request = require('supertest');

3.5.2Douglas Christopher Wilsonbefore adoptiond581592

lines 4–34why, one step back
4
5describe('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 })34

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 35–49why, one step back
35 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 })49

improve proxy trust with ip address listDouglas Christopher Wilsonbefore adoption566720b

lines 50–64why, one step back
50 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 })64

3.5.2Douglas Christopher Wilsonbefore adoptiond581592

lines 65–95why, one step back
65 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})