Skip to content

Commit

Permalink
Merge pull request #47 from hapijs/authority
Browse files Browse the repository at this point in the history
Add authority option. Closes #46
  • Loading branch information
hueniverse committed Oct 5, 2015
2 parents bd09c12 + 857786f commit 1008cc5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions API.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Injects a fake request into an HTTP server.
- `options` - request options object where:
- `url` - a string specifying the request URL.
- `method` - a string specifying the HTTP request method, defaulting to `'GET'`.
- `authority` - a string specifying the HTTP HOST header value is no header is provided and the `url`
does not include an authority component. Defaults to `'localhost'`.
- `headers` - an optional object containing request headers.
- `remoteAddress` - an optional string specifying the client remote address. Defaults to `'127.0.0.1'`.
- `payload` - an optional request payload. Can be a string, Buffer or object.
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internals.Request = function (options) {
});

this.headers['user-agent'] = this.headers['user-agent'] || 'shot';
this.headers.host = this.headers.host || uri.host || 'localhost';
this.headers.host = this.headers.host || uri.host || options.authority || 'localhost';

this.connection = {
remoteAddress: options.remoteAddress || '127.0.0.1'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "shot",
"description": "Injects a fake HTTP request/response into a node HTTP server",
"version": "1.6.1",
"version": "1.7.0",
"repository": "git://github.com/hapijs/shot",
"main": "lib/index.js",
"keywords": [
Expand Down
15 changes: 15 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,21 @@ describe('inject()', function () {
});
});

it('passes authority as host header', function (done) {

var dispatch = function (req, res) {

res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end(req.headers.host);
};

Shot.inject(dispatch, { method: 'get', url: '/hello', authority: 'something' }, function (res) {

expect(res.payload).to.equal('something');
done();
});
});

it('passes uri host as host header', function (done) {

var dispatch = function (req, res) {
Expand Down

0 comments on commit 1008cc5

Please sign in to comment.