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

fix: support existing header instance as argument #5090

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/core/Axios.js
Expand Up @@ -69,8 +69,8 @@ class Axios {

// Flatten headers
const defaultHeaders = config.headers && utils.merge(
config.headers.common,
config.headers[config.method]
this.defaults.headers.common,
this.defaults.headers[config.method]
);

defaultHeaders && utils.forEach(
Expand Down
2 changes: 1 addition & 1 deletion lib/core/AxiosHeaders.js
Expand Up @@ -105,7 +105,7 @@ Object.assign(AxiosHeaders.prototype, {
self[key || _header] = normalizeValue(_value);
}

if (utils.isPlainObject(header)) {
if (utils.isPlainObject(header) || header instanceof AxiosHeaders) {
utils.forEach(header, (_value, _header) => {
setHeader(_value, _header, valueOrRewrite);
});
Expand Down
14 changes: 14 additions & 0 deletions test/unit/core/AxiosHeaders.js
Expand Up @@ -13,6 +13,20 @@ describe('AxiosHeaders', function () {
assert.strictEqual(headers.get('y'), '2');
})

it('should existing header instance as argument', function () {
const headers = new AxiosHeaders({
x: 1,
y: 2,
});

assert.strictEqual(headers.get('x'), '1');
assert.strictEqual(headers.get('y'), '2');

const newHeaders = new AxiosHeaders(headers);

assert.strictEqual(newHeaders.get('x'), '1');
assert.strictEqual(newHeaders.get('y'), '2');
})

describe('set', function () {
it('should support adding a single header', function(){
Expand Down