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
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
var express = require('../') , request = require('./support/http') , assert = require('assert');
describe('req', function(){ describe('.host', function(){ it('should return the Host when present', function(done){ var app = express();
app.use(function(req, res){ res.end(req.host); });
request(app) .post('/') .set('Host', 'example.com') .expect('example.com', done); })
it('should strip port number', function(done){ var app = express();
app.use(function(req, res){ res.end(req.host); });
request(app) .post('/') .set('Host', 'example.com:3000') .expect('example.com', done); })
it('should return undefined otherwise', function(done){ var app = express();
app.use(function(req, res){ req.headers.host = null; res.end(String(req.host)); });
request(app) .post('/') .expect('undefined', done); })
it('should work with IPv6 Host', function(done){ var app = express();
app.use(function(req, res){ res.end(req.host); });
request(app) .post('/') .set('Host', '[::1]') .expect('[::1]', done); })
it('should work with IPv6 Host and port', function(done){ var app = express();
app.use(function(req, res){ res.end(req.host); });
request(app) .post('/') .set('Host', '[::1]:3000') .expect('[::1]', done); }) })})