req.protocol.js
This file
Path
test/req.protocol.js
113 lines · 2.5 KiB · JavaScript
Last changed by
Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
History of this fileTake it
The walk stopped after 200 commits: lines older than 2a0c35a point at it.
Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
line 1why, one step back1'use strict'Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 2–78why, one step back23var express = require('../')4 , request = require('supertest');56describe('req', function(){7 describe('.protocol', function(){8 it('should return the protocol string', function(done){9 var app = express();1011 app.use(function(req, res){12 res.end(req.protocol);13 });1415 request(app)16 .get('/')17 .expect('http', done);18 })1920 describe('when "trust proxy" is enabled', function(){21 it('should respect X-Forwarded-Proto', function(done){22 var app = express();2324 app.enable('trust proxy');2526 app.use(function(req, res){27 res.end(req.protocol);28 });2930 request(app)31 .get('/')32 .set('X-Forwarded-Proto', 'https')33 .expect('https', done);34 })3536 it('should default to the socket addr if X-Forwarded-Proto not present', function(done){37 var app = express();3839 app.enable('trust proxy');4041 app.use(function(req, res){42 req.connection.encrypted = true;43 res.end(req.protocol);44 });4546 request(app)47 .get('/')48 .expect('https', done);49 })5051 it('should ignore X-Forwarded-Proto if socket addr not trusted', function(done){52 var app = express();5354 app.set('trust proxy', '10.0.0.1');5556 app.use(function(req, res){57 res.end(req.protocol);58 });5960 request(app)61 .get('/')62 .set('X-Forwarded-Proto', 'https')63 .expect('http', done);64 })6566 it('should default to http', function(done){67 var app = express();6869 app.enable('trust proxy');7071 app.use(function(req, res){72 res.end(req.protocol);73 });7475 request(app)76 .get('/')77 .expect('http', done);78 })Merge tag '4.12.4'Douglas Christopher Wilsonbefore adoptionf90e045
lines 79–95why, one step back7980 describe('when trusting hop count', function () {81 it('should respect X-Forwarded-Proto', function (done) {82 var app = express();8384 app.set('trust proxy', 1);8586 app.use(function (req, res) {87 res.end(req.protocol);88 });8990 request(app)91 .get('/')92 .set('X-Forwarded-Proto', 'https')93 .expect('https', done);94 })95 })Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 96–113why, one step back96 })9798 describe('when "trust proxy" is disabled', function(){99 it('should ignore X-Forwarded-Proto', function(done){100 var app = express();101102 app.use(function(req, res){103 res.end(req.protocol);104 });105106 request(app)107 .get('/')108 .set('X-Forwarded-Proto', 'https')109 .expect('http', done);110 })111 })112 })113})