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

Overridden headers on multiple instances creation #1009

Closed
emaincourt opened this issue Jul 20, 2017 · 3 comments
Closed

Overridden headers on multiple instances creation #1009

emaincourt opened this issue Jul 20, 2017 · 3 comments

Comments

@emaincourt
Copy link

emaincourt commented Jul 20, 2017

Summary

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.

Context

  • axios version: e.g.: v0.16.2
  • Environment: e.g.: node v6.9.2
@Pyrolistical
Copy link

I wish i could write first.headers.authorization = 'foo' and have it change for that instance

@emaincourt
Copy link
Author

Well the only way to bypass this limitation seems to be forcing the header value :

first.get('/posts', {
    headers: {
        authorization: 'foo',
    },
})

@rubennorte
Copy link
Member

This is part of a greater issue that we're going to address soon (and way later than it's reasonable). See #812.

@axios axios locked and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants