koa-lite/test/request/host.js
dead_horse 72a9b69146 add request.hostname(getter), fixed #224
make request.host and request.hostname work as node url lib
http://nodejs.org/api/url.html#url_url
this commit will change older request.host(getter)
2014-02-26 14:03:05 +08:00

40 lines
1.1 KiB
JavaScript

var request = require('../context').request;
describe('req.host', function(){
it('should return host with port', function(){
var req = request();
req.header.host = 'foo.com:3000';
req.host.should.equal('foo.com:3000');
})
describe('when X-Forwarded-Host is present', function(){
describe('and proxy is not trusted', function(){
it('should be ignored', function(){
var req = request();
req.header['x-forwarded-host'] = 'bar.com';
req.header['host'] = 'foo.com';
req.host.should.equal('foo.com')
})
})
describe('and proxy is trusted', function(){
it('should be used', function(){
var req = request();
req.app.proxy = true;
req.header['x-forwarded-host'] = 'bar.com, baz.com';
req.header['host'] = 'foo.com';
req.host.should.equal('bar.com')
})
})
})
})
describe('req.host=', function(){
it('should replace the host', function(){
var req = request();
req.header['host'] = 'foo.com';
req.host = 'bar.com';
req.host.should.equal('bar.com')
})
})