Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

axios request interceptor adds additional headers #4843

Open
eau-de-la-seine opened this issue Jul 12, 2022 · 0 comments
Open

axios request interceptor adds additional headers #4843

eau-de-la-seine opened this issue Jul 12, 2022 · 0 comments

Comments

@eau-de-la-seine
Copy link

Describe the bug

axios request interceptor adds additional headers

To Reproduce

axios.interceptors.request.use(config => {
    console.log('config.headers')
    console.log(config.headers)
    return config
}, error => {
    return Promise.reject(error)
})

await axios.get(url, {
    headers: {"X-header1": 'headerValue1'}
})

Console Log result:

config.headers
{
  common: { Accept: 'application/json, text/plain, */*' },
  delete: {},
  get: {},
  head: {},
  post: { 'Content-Type': 'application/x-www-form-urlencoded' },
  put: { 'Content-Type': 'application/x-www-form-urlencoded' },
  patch: { 'Content-Type': 'application/x-www-form-urlencoded' },
  'X-header1': 'headerValue1'
}

Problem: common, delete, get, head, post, put, patch have been added to config.headers by axios

Expected behavior

Expected Console Log result:

config.headers
{
  'X-header1': 'headerValue1'
}

Environment

NodeJS Back-end project using ES6 modules and testing with Jasmine (the only testing framework that works without additional transpiler for ES6 projects)

  • Axios Version ^0.27.2
  • Node.js Version v14.17.0
  • OS: Ubuntu 20.04.4 LTS
  • Additional Library Versions: Jasmine ^4.2.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant