Skip to content
This repository has been archived by the owner on Feb 27, 2022. It is now read-only.

Commit

Permalink
feat(request): support for adding headers
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Aug 28, 2017
1 parent e50291f commit 2659ee6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/Request/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,36 @@ module.exports = function () {
super()
this.Config = Config
this._cookies = []
this._headers = []
this._hooks = {
before: [],
after: []
}
}

/**
* Returns an array of cookies to be
* An array of cookies to be
* set as header
*
* @method cookies
* @attribute cookies
*
* @return {Array}
*/
get cookies () {
return this._cookies
}

/**
* Array of request headers
*
* @attribute headers
*
* @return {Array}
*/
get headers () {
return this._headers
}

/**
* Add a cookie to the request
*
Expand All @@ -61,6 +73,21 @@ module.exports = function () {
return this
}

/**
* Set request header/headers
*
* @method header
*
* @param {String} key
* @param {Object} value
*
* @chainable
*/
header (key, value) {
this._headers.push({ key, value })
return this
}

/**
* Add a new hook before request starts
*
Expand Down
6 changes: 6 additions & 0 deletions test/unit/request.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,10 @@ test.group('Request', (group) => {
})
await request.exec('before')
})

test('add request header', (assert) => {
const request = new Request(new Config())
request.header('Auth', '123')
assert.deepEqual(request.headers, [{ key: 'Auth', value: '123' }])
})
})

0 comments on commit 2659ee6

Please sign in to comment.