From 5ca9f451a72cac52e6c098b3774551a8cda97d0e Mon Sep 17 00:00:00 2001 From: dead_horse Date: Mon, 4 Aug 2014 11:26:07 +0800 Subject: [PATCH] alias request.headers as request.header --- docs/api/request.md | 4 ++++ lib/context.js | 1 + lib/request.js | 11 +++++++++++ test/request/headers.js | 9 +++++++++ 4 files changed, 25 insertions(+) create mode 100644 test/request/headers.js diff --git a/docs/api/request.md b/docs/api/request.md index ee6ab9c..3a281a8 100644 --- a/docs/api/request.md +++ b/docs/api/request.md @@ -10,6 +10,10 @@ Request header object. +### req.headers + + Request header object. Alias as `req.header`. + ### req.method Request method. diff --git a/lib/context.js b/lib/context.js index 02b85d5..b187c87 100644 --- a/lib/context.js +++ b/lib/context.js @@ -169,6 +169,7 @@ delegate(proto, 'request') .getter('host') .getter('hostname') .getter('header') + .getter('headers') .getter('secure') .getter('stale') .getter('fresh') diff --git a/lib/request.js b/lib/request.js index 2047016..7b7d4e0 100644 --- a/lib/request.js +++ b/lib/request.js @@ -27,6 +27,17 @@ module.exports = { return this.req.headers; }, + /** + * Return request header, alias as request.header + * + * @return {Object} + * @api public + */ + + get headers() { + return this.req.headers; + }, + /** * Get request URL. * diff --git a/test/request/headers.js b/test/request/headers.js new file mode 100644 index 0000000..7a85975 --- /dev/null +++ b/test/request/headers.js @@ -0,0 +1,9 @@ + +var request = require('../context').request; + +describe('req.headers', function(){ + it('should return the request header object', function(){ + var req = request(); + req.headers.should.equal(req.req.headers); + }) +})