Skip to content

Commit

Permalink
add a way to delete a header (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeam authored and skellock committed Apr 19, 2017
1 parent 5d4353c commit 85e5dd9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/apisauce.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ export const create = config => {
return instance
}

// remove header
const deleteHeader = (name) => {
delete headers[name]
return instance
}

/**
* Sets a new base URL.
*/
Expand Down Expand Up @@ -320,6 +326,7 @@ export const create = config => {
addResponseTransform,
setHeader,
setHeaders,
deleteHeader,
headers,
setBaseURL,
getBaseURL,
Expand Down
5 changes: 5 additions & 0 deletions test/headers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ test('jumps the wire with the right headers', async t => {
api.setHeader('steve', 'thx')
const response2 = await api.get('/number/200', {})
t.is(response2.config.headers['steve'], 'thx')

// then remove one of them
api.deleteHeader('steve')
const response3 = await api.get('/number/200', {})
t.is(response3.config.headers['steve'], undefined)
})

0 comments on commit 85e5dd9

Please sign in to comment.