Skip to content
Myr

req.host.js

This file

Path

test/req.host.js

138 lines · 3.0 KiB · JavaScript

Last changed by

remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3

History of this file

Take it

The walk stopped after 200 commits: lines older than a10f695 point at it.

pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695

lines 1–2why, one step back
1
2var express = require('../')

remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3

line 3why, one step back
3 , request = require('supertest')

pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695

lines 4–20why, one step back
4 , assert = require('assert');
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 })20

Merge branch '3.5.x' into 3.xDouglas Christopher Wilsonbefore adoption66b38b5

lines 21–33why, one step back
21 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')31 .expect('example.com', done);32 })33

pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695

lines 34–44why, one step back
34 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);

Merge branch '3.5.x' into 3.xDouglas Christopher Wilsonbefore adoption66b38b5

lines 45–70why, one step back
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')70 .expect('[::1]', done);

pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695

line 71why, one step back
71 })

improve proxy trust with ip address listDouglas Christopher Wilsonbefore adoption566720b

lines 72–136why, one step back
72
73 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 })120 })121122 describe('when "trust proxy" is disabled', function(){123 it('should ignore X-Forwarded-Host', function(done){124 var app = express();125126 app.use(function(req, res){127 res.end(req.host);128 });129130 request(app)131 .get('/')132 .set('Host', 'localhost')133 .set('X-Forwarded-Host', 'evil')134 .expect('localhost', done);135 })136 })

pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695

lines 137–138why, one step back
137 })
138})