I've noticed that when multiple instances of axios get created with custom headers configuration, the latest one will override any other previously defined configuration. Here is the simplest code snippet to reproduce it :
const axios = require('axios');
const baseURL = '';
const first = axios.create({ baseURL });
first.defaults.headers.common.authorization = 'foo';
const second = axios.create({ baseURL });
second.defaults.headers.common.authorization = 'bar';
console.log(first.defaults.headers.common);
Results in :
Object
Accept: "application/json, text/plain, */*"
authorization: "bar"
...
I am not sure this is the correct behavior since instances are supposed to be independant.
I wish i could write first.headers.authorization = 'foo'
and have it change for that instance
Well the only way to bypass this limitation seems to be forcing the header value :
first.get('/posts', {
headers: {
authorization: 'foo',
},
})
This is part of a greater issue that we're going to address soon (and way later than it's reasonable). See #812.
Most helpful comment
This is part of a greater issue that we're going to address soon (and way later than it's reasonable). See #812.