feat: alias response.headers to response.header
This commit is contained in:
parent
4b83a5a96c
commit
1c5cb6f691
3 changed files with 34 additions and 0 deletions
|
@ -10,6 +10,11 @@
|
|||
|
||||
Response header object.
|
||||
|
||||
### response.headers
|
||||
|
||||
Response header object. Alias as `response.header`.
|
||||
|
||||
|
||||
### response.socket
|
||||
|
||||
Request socket.
|
||||
|
|
|
@ -47,6 +47,17 @@ module.exports = {
|
|||
return this.res._headers || {};
|
||||
},
|
||||
|
||||
/**
|
||||
* Return response header, alias as response.header
|
||||
*
|
||||
* @return {Object}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
get headers() {
|
||||
return this.header;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get response status code.
|
||||
*
|
||||
|
|
18
test/response/headers.js
Normal file
18
test/response/headers.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
|
||||
var response = require('../context').response;
|
||||
|
||||
describe('res.header', function(){
|
||||
it('should return the response header object', function(){
|
||||
var res = response();
|
||||
res.set('X-Foo', 'bar');
|
||||
res.headers.should.eql({ 'x-foo': 'bar' });
|
||||
})
|
||||
|
||||
describe('when res._headers not present', function (){
|
||||
it('should return empty object', function (){
|
||||
var res = response();
|
||||
res.res._headers = null;
|
||||
res.headers.should.eql({});
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Reference in a new issue