From 1c5cb6f6913ca6a963ecbe6de91d3aa66c3b2cff Mon Sep 17 00:00:00 2001 From: dead_horse Date: Thu, 23 Apr 2015 17:28:02 +0800 Subject: [PATCH] feat: alias response.headers to response.header --- docs/api/response.md | 5 +++++ lib/response.js | 11 +++++++++++ test/response/headers.js | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 test/response/headers.js diff --git a/docs/api/response.md b/docs/api/response.md index 408e32d..a5a4ac6 100644 --- a/docs/api/response.md +++ b/docs/api/response.md @@ -10,6 +10,11 @@ Response header object. +### response.headers + + Response header object. Alias as `response.header`. + + ### response.socket Request socket. diff --git a/lib/response.js b/lib/response.js index 9ae61c0..4a8a6e3 100644 --- a/lib/response.js +++ b/lib/response.js @@ -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. * diff --git a/test/response/headers.js b/test/response/headers.js new file mode 100644 index 0000000..33087c4 --- /dev/null +++ b/test/response/headers.js @@ -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({}); + }) + }) +})