Skip to content

Commit

Permalink
feat(headers): do not overwrite the Authorization header (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenpetryk authored and Phoebe Schmidt committed Mar 7, 2019
1 parent 7279d73 commit 904791b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/create-http-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ export default function createHttpClient (axios, options) {

const baseURL = options.baseURL || `${protocol}://${hostname}:${port}${config.basePath}/spaces/${space}`

config.headers['Authorization'] = 'Bearer ' + config.accessToken
if (!config.headers['Authorization']) {
config.headers['Authorization'] = 'Bearer ' + config.accessToken
}

// Set these headers only for node because browsers don't like it when you
// override user-agent or accept-encoding.
Expand Down
17 changes: 17 additions & 0 deletions test/unit/create-http-client-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ test('Calls axios based on passed hostname with insecure flag', t => {
t.end()
})

test('Calls axios based on passed headers', t => {
setup()
createHttpClient(axios, {
accessToken: 'clientAccessToken',
headers: {
'X-Custom-Header': 'example',
Authorization: 'Basic customAuth'
}
})

t.equals(axios.create.args[0][0].headers['X-Custom-Header'], 'example')
t.equals(axios.create.args[0][0].headers['Authorization'], 'Basic customAuth')

teardown()
t.end()
})

test('Calls axios with reques/response logger', t => {
setup()
createHttpClient(axios, {
Expand Down

0 comments on commit 904791b

Please sign in to comment.