Skip to content
Myr

req.protocol.js

This file

Path

test/req.protocol.js

77 lines · 1.6 KiB · JavaScript

Last changed by

Added "trust proxy" settingTJ Holowaychukbefore adoption4d87efc

History of this file

Take it

Added `req.protocol()`TJ Holowaychukbefore adoption2ba343d

lines 1–5why, one step back
1
2var express = require('../')3 , request = require('./support/http');45describe('req', function(){

Added "trust proxy" settingTJ Holowaychukbefore adoption4d87efc

line 6why, one step back
6 describe('.protocol', function(){

Added `req.protocol()`TJ Holowaychukbefore adoption2ba343d

lines 7–10why, one step back
7 it('should return the protocol string', function(done){
8 var app = express();910 app.use(function(req, res){

Added "trust proxy" settingTJ Holowaychukbefore adoption4d87efc

line 11why, one step back
11 res.end(req.protocol);

Added `req.protocol()`TJ Holowaychukbefore adoption2ba343d

lines 12–21why, one step back
12 });
1314 request(app)15 .get('/')16 .end(function(res){17 res.body.should.equal('http');18 done();19 })20 })21

Added "trust proxy" settingTJ Holowaychukbefore adoption4d87efc

line 22why, one step back
22 describe('when "trust proxy" is enabled', function(){

Added `req.protocol()`TJ Holowaychukbefore adoption2ba343d

lines 23–25why, one step back
23 it('should respect X-Forwarded-Proto', function(done){
24 var app = express();25

Added "trust proxy" settingTJ Holowaychukbefore adoption4d87efc

lines 26–27why, one step back
26 app.enable('trust proxy');
27

Added `req.protocol()`TJ Holowaychukbefore adoption2ba343d

line 28why, one step back
28 app.use(function(req, res){

Added "trust proxy" settingTJ Holowaychukbefore adoption4d87efc

line 29why, one step back
29 res.end(req.protocol);

Added `req.protocol()`TJ Holowaychukbefore adoption2ba343d

lines 30–43why, one step back
30 });
3132 request(app)33 .get('/')34 .set('X-Forwarded-Proto', 'https')35 .end(function(res){36 res.body.should.equal('https');37 done();38 })39 })4041 it('should default to http', function(done){42 var app = express();43

Added "trust proxy" settingTJ Holowaychukbefore adoption4d87efc

lines 44–45why, one step back
44 app.enable('trust proxy');
45

Added `req.protocol()`TJ Holowaychukbefore adoption2ba343d

line 46why, one step back
46 app.use(function(req, res){

Added "trust proxy" settingTJ Holowaychukbefore adoption4d87efc

line 47why, one step back
47 res.end(req.protocol);

Added `req.protocol()`TJ Holowaychukbefore adoption2ba343d

lines 48–58why, one step back
48 });
4950 request(app)51 .get('/')52 .end(function(res){53 res.body.should.equal('http');54 done();55 })56 })57 })58

Added "trust proxy" settingTJ Holowaychukbefore adoption4d87efc

line 59why, one step back
59 describe('when "trust proxy" is disabled', function(){

Added `req.protocol()`TJ Holowaychukbefore adoption2ba343d

lines 60–63why, one step back
60 it('should ignore X-Forwarded-Proto', function(done){
61 var app = express();6263 app.use(function(req, res){

Added "trust proxy" settingTJ Holowaychukbefore adoption4d87efc

line 64why, one step back
64 res.end(req.protocol);

Added `req.protocol()`TJ Holowaychukbefore adoption2ba343d

lines 65–77why, one step back
65 });
6667 request(app)68 .get('/')69 .set('X-Forwarded-Proto', 'https')70 .end(function(res){71 res.body.should.equal('http');72 done();73 })74 })75 })76 })77})