req.host.js
This file
Path
test/req.host.js
156 lines · 3.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–30why, one step back23var express = require('../')4 , request = require('supertest')56describe('req', function(){7 describe('.host', function(){8 it('should return the Host when present', function(done){9 var app = express();1011 app.use(function(req, res){12 res.end(req.host);13 });1415 request(app)16 .post('/')17 .set('Host', 'example.com')18 .expect('example.com', done);19 })2021 it('should strip port number', function(done){22 var app = express();2324 app.use(function(req, res){25 res.end(req.host);26 });2728 request(app)29 .post('/')30 .set('Host', 'example.com:3000')Change req.host to return hostDouglas Christopher Wilsonbefore adoption085a296
line 31why, one step back31 .expect(200, 'example.com:3000', done);Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 32–69why, one step back32 })3334 it('should return undefined otherwise', function(done){35 var app = express();3637 app.use(function(req, res){38 req.headers.host = null;39 res.end(String(req.host));40 });4142 request(app)43 .post('/')44 .expect('undefined', done);45 })4647 it('should work with IPv6 Host', function(done){48 var app = express();4950 app.use(function(req, res){51 res.end(req.host);52 });5354 request(app)55 .post('/')56 .set('Host', '[::1]')57 .expect('[::1]', done);58 })5960 it('should work with IPv6 Host and port', function(done){61 var app = express();6263 app.use(function(req, res){64 res.end(req.host);65 });6667 request(app)68 .post('/')69 .set('Host', '[::1]:3000')Change req.host to return hostDouglas Christopher Wilsonbefore adoption085a296
line 70why, one step back70 .expect(200, '[::1]:3000', done);Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 71–119why, one step back71 })7273 describe('when "trust proxy" is enabled', function(){74 it('should respect X-Forwarded-Host', function(done){75 var app = express();7677 app.enable('trust proxy');7879 app.use(function(req, res){80 res.end(req.host);81 });8283 request(app)84 .get('/')85 .set('Host', 'localhost')86 .set('X-Forwarded-Host', 'example.com')87 .expect('example.com', done);88 })8990 it('should ignore X-Forwarded-Host if socket addr not trusted', function(done){91 var app = express();9293 app.set('trust proxy', '10.0.0.1');9495 app.use(function(req, res){96 res.end(req.host);97 });9899 request(app)100 .get('/')101 .set('Host', 'localhost')102 .set('X-Forwarded-Host', 'example.com')103 .expect('localhost', done);104 })105106 it('should default to Host', function(done){107 var app = express();108109 app.enable('trust proxy');110111 app.use(function(req, res){112 res.end(req.host);113 });114115 request(app)116 .get('/')117 .set('Host', 'example.com')118 .expect('example.com', done);119 })Merge tag '4.12.4'Douglas Christopher Wilsonbefore adoptionf90e045
lines 120–137why, one step back120121 describe('when trusting hop count', function () {122 it('should respect X-Forwarded-Host', function (done) {123 var app = express();124125 app.set('trust proxy', 1);126127 app.use(function (req, res) {128 res.end(req.host);129 });130131 request(app)132 .get('/')133 .set('Host', 'localhost')134 .set('X-Forwarded-Host', 'example.com')135 .expect('example.com', done);136 })137 })Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 138–156why, one step back138 })139140 describe('when "trust proxy" is disabled', function(){141 it('should ignore X-Forwarded-Host', function(done){142 var app = express();143144 app.use(function(req, res){145 res.end(req.host);146 });147148 request(app)149 .get('/')150 .set('Host', 'localhost')151 .set('X-Forwarded-Host', 'evil')152 .expect('localhost', done);153 })154 })155 })156})