feat: alias response.headers to response.header

This commit is contained in:
dead_horse 2015-04-23 17:28:02 +08:00
parent 4b83a5a96c
commit 1c5cb6f691
3 changed files with 34 additions and 0 deletions

View file

@ -10,6 +10,11 @@
Response header object. Response header object.
### response.headers
Response header object. Alias as `response.header`.
### response.socket ### response.socket
Request socket. Request socket.

View file

@ -47,6 +47,17 @@ module.exports = {
return this.res._headers || {}; return this.res._headers || {};
}, },
/**
* Return response header, alias as response.header
*
* @return {Object}
* @api public
*/
get headers() {
return this.header;
},
/** /**
* Get response status code. * Get response status code.
* *

18
test/response/headers.js Normal file
View 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({});
})
})
})