-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request koajs#225 from dead-horse/issue224-host-confused
add request.hostname(getter), fixed koajs#224
- Loading branch information
Showing
4 changed files
with
52 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
var request = require('../context').request; | ||
|
||
describe('req.hostname', function(){ | ||
it('should return hostname void of port', function(){ | ||
var req = request(); | ||
req.header.host = 'foo.com:3000'; | ||
req.hostname.should.equal('foo.com'); | ||
}) | ||
|
||
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.hostname.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.hostname.should.equal('bar.com') | ||
}) | ||
}) | ||
}) | ||
}) |