Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to delete a header #95

Merged
merged 1 commit into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})