req.host.js
This file
Path
test/req.host.js
73 lines · 1.5 KiB · JavaScript
Last changed by
Fix req.host for IPv6 literalsDouglas Christopher Wilsonbefore adoptionc99fa6a
History of this fileTake it
add req.host testsTJ Holowaychukbefore adoption28ca1b5
lines 1–19why, one step back12var express = require('../')3 , request = require('./support/http')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 })fix `req.host` when no Host is present, return undefinedTJ Holowaychukbefore adoption06ead58
line 20why, one step back20Fix req.host for IPv6 literalsDouglas Christopher Wilsonbefore adoptionc99fa6a
lines 21–33why, one step back21 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 })33fix `req.host` when no Host is present, return undefinedTJ Holowaychukbefore adoption06ead58
lines 34–44why, one step back34 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);Fix req.host for IPv6 literalsDouglas Christopher Wilsonbefore adoptionc99fa6a
lines 45–70why, one step back45 })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);fix `req.host` when no Host is present, return undefinedTJ Holowaychukbefore adoption06ead58
line 71why, one step back71 })add req.host testsTJ Holowaychukbefore adoption28ca1b5
lines 72–73why, one step back72 })73})