overwrite/delete headers from axios.create instance
See original GitHub issueHi there, is the follow behavior a bug or not intend:
if i create a axios instance with a header like this
const HTTP = axios.create({
baseURL: 'test.test',
headers: {
'X-Foo': 'value',
},
});
it is no longer possible to overwrite/delete the header like
HTTP({ url: 'other', baseURL: null, headers: null })
baseUrl and url can be overwritten, headers not. why. respectively how i can?
Environment:
- Axios Version latest
❤️ axios
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Using Axios to set request headers - LogRocket Blog
To correctly set up the headers for each request, we can create an instance of Axios using axios.create and then set a custom...
Read more >Config Defaults | Axios Docs
Set config defaults when creating the instance const instance ... instance has been created instance.defaults.headers.common['Authorization'] = AUTH_TOKEN; ...
Read more >Axios - update headers on exported axios.create instance
I have one api.js which exports by default an axios.create() instance:
Read more >Setting Request Headers with Axios - Mastering JS
Learn how to set HTTP request headers on GET and POST requests with the Axios HTTP client.
Read more >How To Set Request Headers Using Axios? - RapidAPI
HTTP headers allow clients and servers to talk to each other and pass ... Axios allows us to create new instances with custom...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@webdesignberlin this is due to parameters now being deep merged, though I do like the idea of being able to overwrite the whole headers object in one go. There is actually no workaround, you could set the property
headers.X-Foo
to null. However, once the header has been added to the instance it seems to not be possible to clear it completely. I will see if there is a way to have both deep merge as well as a way to completely clear the headers.@webdesignberlin Do you confirm that case3 works for you? I tested with following script,
Both v0.19.0 and v0.21.1 have the same output. The config merging is working as expected. The reason why post method will still have headers is due to the default
transformRequest
adds for object data.