You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
User-Agent set in global and instance defaults are not respected #5157
Setting User-Agent in global and instance default config is not respected by Axios when sending a request.
To Reproduce
constaxios=require("axios"),axiosInstance=axios.create(),// view the webhook result @ https://webhook.site/#!/a9845fd3-dfca-4dda-aa4c-0cd5e7a092b2// or get new webhook endpoint and replace the following.webhookUrl='https://webhook.site/a9845fd3-dfca-4dda-aa4c-0cd5e7a092b2';// Global Configaxios.defaults.headers.common['User-Agent']='global-bug-test/1.0.0';// Instance ConfigaxiosInstance.defaults.headers.common['User-Agent']='instance-bug-test/1.0.0';// GET request to webhook urlletreq=awaitaxios.get(webhookUrl);console.log(`global user agent: ${req.request.getHeader('User-Agent')}`);// expected to be "global-bug-test/1.0.0"req=awaitaxiosInstance.get(webhookUrl);console.log(`instance user agent: ${req.request.getHeader('User-Agent')}`);// expected to be "instance-bug-test/1.0.0"req=awaitaxios({method: 'get',url: webhookUrl,headers: {'User-Agent': 'per-req/1.0.0'}});console.log(`per request user agent: ${req.request.getHeader('User-Agent')}`);// as expected 'per-req/1.0.0'req=awaitaxiosInstance({method: 'get',url: webhookUrl,headers: {'User-Agent': 'instance-per-req/1.0.0'}});console.log(`instance per request user agent: ${req.request.getHeader('User-Agent')}`);// as expected 'instance-per-req/1.0.0'
I got same issue. I want to set header Authorization when login success like :
axios.defaults.headers.common['Authorization'] = 'Bearer TOKEN_AUTH'
But when I make another request, the header not include at that request. I also tried with Axios Interceptor, but got some result.
I hope this issue can be fixed.
Thanks before.
Activity
rizaldimaulidia commentedon Oct 22, 2022
I got same issue. I want to set header Authorization when login success like :
axios.defaults.headers.common['Authorization'] = 'Bearer TOKEN_AUTH'
But when I make another request, the header not include at that request. I also tried with Axios Interceptor, but got some result.
I hope this issue can be fixed.
Thanks before.
Axios v1.1.3
Node.JS v12.22.9
jasonsaayman commentedon Nov 10, 2022
Hi 👋
Please try the latest pre-release by running the following:
Please provide feedback in either the pinned issue or discussion thread 🧵