From 012587889d67464316ada42eeb525367756075be Mon Sep 17 00:00:00 2001 From: Martin fl0w Iwanowski Date: Sun, 18 Jun 2017 01:02:47 +0200 Subject: [PATCH] added setters for header and headers, fixes #991 --- docs/api/request.md | 8 ++++++++ lib/request.js | 20 ++++++++++++++++++++ test/request/header.js | 6 ++++++ test/request/headers.js | 6 ++++++ 4 files changed, 40 insertions(+) diff --git a/docs/api/request.md b/docs/api/request.md index 4479800..9b49447 100644 --- a/docs/api/request.md +++ b/docs/api/request.md @@ -10,10 +10,18 @@ Request header object. +### request.header= + + Set request header object. + ### request.headers Request header object. Alias as `request.header`. +### request.headers= + + Set request header object. Alias as `request.header=`. + ### request.method Request method. diff --git a/lib/request.js b/lib/request.js index 5c9a241..1e31754 100644 --- a/lib/request.js +++ b/lib/request.js @@ -31,6 +31,16 @@ module.exports = { return this.req.headers; }, + /** + * Set request header. + * + * @api public + */ + + set header(val) { + this.req.headers = val; + }, + /** * Return request header, alias as request.header * @@ -42,6 +52,16 @@ module.exports = { return this.req.headers; }, + /** + * Set request header, alias as request.header + * + * @api public + */ + + set headers(val) { + this.req.headers = val; + }, + /** * Get request URL. * diff --git a/test/request/header.js b/test/request/header.js index 9dd207c..9e6ebff 100644 --- a/test/request/header.js +++ b/test/request/header.js @@ -9,4 +9,10 @@ describe('req.header', () => { const req = request(); assert.deepEqual(req.header, req.req.headers); }); + + it('should set the request header object', () => { + const req = request(); + req.header = {'X-Custom-Headerfield': 'Its one header, with headerfields'}; + assert.deepEqual(req.header, req.req.headers); + }); }); diff --git a/test/request/headers.js b/test/request/headers.js index c3981e9..a96da2c 100644 --- a/test/request/headers.js +++ b/test/request/headers.js @@ -9,4 +9,10 @@ describe('req.headers', () => { const req = request(); assert.deepEqual(req.headers, req.req.headers); }); + + it('should set the request header object', () => { + const req = request(); + req.headers = {'X-Custom-Headerfield': 'Its one header, with headerfields'}; + assert.deepEqual(req.headers, req.req.headers); + }); });