added setters for header and headers, fixes #991

This commit is contained in:
Martin fl0w Iwanowski 2017-06-18 01:02:47 +02:00 committed by jongleberry
parent f6f1ab73e1
commit 012587889d
4 changed files with 40 additions and 0 deletions

View file

@ -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.

View file

@ -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.
*

View file

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

View file

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