fix(deps)!: mime-types@^3.0.0 (#5882)
[express.git] / test / req.protocol.js
blob61f76356b4ce284050c5bb68dc87d3eef4fe9a6b
1 'use strict'
3 var express = require('../')
4 , request = require('supertest');
6 describe('req', function(){
7 describe('.protocol', function(){
8 it('should return the protocol string', function(done){
9 var app = express();
11 app.use(function(req, res){
12 res.end(req.protocol);
13 });
15 request(app)
16 .get('/')
17 .expect('http', done);
20 describe('when "trust proxy" is enabled', function(){
21 it('should respect X-Forwarded-Proto', function(done){
22 var app = express();
24 app.enable('trust proxy');
26 app.use(function(req, res){
27 res.end(req.protocol);
28 });
30 request(app)
31 .get('/')
32 .set('X-Forwarded-Proto', 'https')
33 .expect('https', done);
36 it('should default to the socket addr if X-Forwarded-Proto not present', function(done){
37 var app = express();
39 app.enable('trust proxy');
41 app.use(function(req, res){
42 req.connection.encrypted = true;
43 res.end(req.protocol);
44 });
46 request(app)
47 .get('/')
48 .expect('https', done);
51 it('should ignore X-Forwarded-Proto if socket addr not trusted', function(done){
52 var app = express();
54 app.set('trust proxy', '10.0.0.1');
56 app.use(function(req, res){
57 res.end(req.protocol);
58 });
60 request(app)
61 .get('/')
62 .set('X-Forwarded-Proto', 'https')
63 .expect('http', done);
66 it('should default to http', function(done){
67 var app = express();
69 app.enable('trust proxy');
71 app.use(function(req, res){
72 res.end(req.protocol);
73 });
75 request(app)
76 .get('/')
77 .expect('http', done);
80 describe('when trusting hop count', function () {
81 it('should respect X-Forwarded-Proto', function (done) {
82 var app = express();
84 app.set('trust proxy', 1);
86 app.use(function (req, res) {
87 res.end(req.protocol);
88 });
90 request(app)
91 .get('/')
92 .set('X-Forwarded-Proto', 'https')
93 .expect('https', done);
98 describe('when "trust proxy" is disabled', function(){
99 it('should ignore X-Forwarded-Proto', function(done){
100 var app = express();
102 app.use(function(req, res){
103 res.end(req.protocol);
106 request(app)
107 .get('/')
108 .set('X-Forwarded-Proto', 'https')
109 .expect('http', done);