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); + }); });