What is the difference between headers set in axiosInstance.default.headers and in axiosInstance.default.headers.common? #6601
Unanswered
LeonardThomasSenacor
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
While setting an Accept header for an AxiosInstance, I noticed that when the headers are passed initially via
const instance = axios.create({headers: {Accept: 'application/json'}})
, the header will be set underinstance.defaults.headers.Accept
.But wherever I read about overwriting default headers of axios it always mentions overwriting the header under
instance.defaults.headers.common
(see also https://www.npmjs.com/package/axios#custom-instance-defaults). Moreover, whether I callaxios.create({headers: {Accept: 'application/json'}})
oraxios.create()
, the value ofinstance.defaults.headers.common.Accept
will be 'application/json, text/plain, /', so the headers passed during create do not influence what's under common. I can only manually overwrite it withinstance.defaults.headers.common = {Accept: 'application/json'}
So which one takes precedence?
instance.defaults.headers.Accept
orinstance.defaults.headers.common.Accept
? I know that if I set it for example directly forinstance.defaults.headers.post.Accept
, then this one will take precedence because it is more specific.Or is this a bug in axios 1.7.7 and
instance.defaults.headers.Accept
should not even be possible?Beta Was this translation helpful? Give feedback.
All reactions