2 var express = require('../')
3 , request = require('supertest');
5 describe('req', function(){
6 describe('.protocol', function(){
7 it('should return the protocol string', function(done){
10 app.use(function(req, res){
11 res.end(req.protocol);
16 .expect('http', done);
19 describe('when "trust proxy" is enabled', function(){
20 it('should respect X-Forwarded-Proto', function(done){
23 app.enable('trust proxy');
25 app.use(function(req, res){
26 res.end(req.protocol);
31 .set('X-Forwarded-Proto', 'https')
32 .expect('https', done);
35 it('should default to the socket addr if X-Forwarded-Proto not present', function(done){
38 app.enable('trust proxy');
40 app.use(function(req, res){
41 req.connection.encrypted = true;
42 res.end(req.protocol);
47 .expect('https', done);
50 it('should ignore X-Forwarded-Proto if socket addr not trusted', function(done){
53 app.set('trust proxy', '10.0.0.1');
55 app.use(function(req, res){
56 res.end(req.protocol);
61 .set('X-Forwarded-Proto', 'https')
62 .expect('http', done);
65 it('should default to http', function(done){
68 app.enable('trust proxy');
70 app.use(function(req, res){
71 res.end(req.protocol);
76 .expect('http', done);
79 describe('when trusting hop count', function () {
80 it('should respect X-Forwarded-Proto', function (done) {
83 app.set('trust proxy', 1);
85 app.use(function (req, res) {
86 res.end(req.protocol);
91 .set('X-Forwarded-Proto', 'https')
92 .expect('https', done);
97 describe('when "trust proxy" is disabled', function(){
98 it('should ignore X-Forwarded-Proto', function(done){
101 app.use(function(req, res){
102 res.end(req.protocol);
107 .set('X-Forwarded-Proto', 'https')
108 .expect('http', done);