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(headers): added support for setting header names that overlap with class methods; #5831

Merged
merged 22 commits into from Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3f2f496
chore(ci): Add release-it script;
DigitalBrainJS Dec 10, 2022
1bfc41b
Merge branch 'chore/release-it' into v1.x
DigitalBrainJS Dec 10, 2022
acaf0f4
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 15, 2022
8a5de86
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 15, 2022
cff9271
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 17, 2022
67afe20
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 19, 2022
dc7b66d
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 22, 2022
716eb59
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 23, 2022
10216bf
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 29, 2022
3b199f4
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 7, 2023
f3d444f
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 19, 2023
077c381
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 26, 2023
f598657
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 31, 2023
7bf5713
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Feb 5, 2023
81a8bd6
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Mar 8, 2023
f8bb158
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Apr 5, 2023
3f1c768
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Apr 18, 2023
a9b0418
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Apr 25, 2023
1a16f4e
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Apr 27, 2023
5e22e2f
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS May 10, 2023
b7c77b0
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Aug 25, 2023
eed56c1
fix(headers): added support for headers names overlapped by class met…
DigitalBrainJS Aug 25, 2023
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
1 change: 1 addition & 0 deletions .eslintrc.cjs
Expand Up @@ -10,5 +10,6 @@ module.exports = {
"sourceType": "module"
},
"rules": {
"no-cond-assign": 0
}
}
12 changes: 11 additions & 1 deletion lib/core/AxiosHeaders.js
Expand Up @@ -282,7 +282,17 @@ class AxiosHeaders {

AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent', 'Authorization']);

utils.freezeMethods(AxiosHeaders.prototype);
// reserved names hotfix
utils.reduceDescriptors(AxiosHeaders.prototype, ({value}, key) => {
let mapped = key[0].toUpperCase() + key.slice(1); // map `set` => `Set`
return {
get: () => value,
set(headerValue) {
this[mapped] = headerValue;
}
}
});

utils.freezeMethods(AxiosHeaders);

export default AxiosHeaders;
5 changes: 3 additions & 2 deletions lib/utils.js
Expand Up @@ -540,8 +540,9 @@ const reduceDescriptors = (obj, reducer) => {
const reducedDescriptors = {};

forEach(descriptors, (descriptor, name) => {
if (reducer(descriptor, name, obj) !== false) {
reducedDescriptors[name] = descriptor;
let ret;
if ((ret = reducer(descriptor, name, obj)) !== false) {
reducedDescriptors[name] = ret || descriptor;
}
});

Expand Down
11 changes: 11 additions & 0 deletions test/unit/core/AxiosHeaders.js
Expand Up @@ -76,6 +76,17 @@ describe('AxiosHeaders', function () {
})
});

it('should support uppercase name mapping for names overlapped by class methods', () => {
const headers = new AxiosHeaders({
set: 'foo'
});

headers.set('get', 'bar');

assert.strictEqual(headers.get('Set'), 'foo');
assert.strictEqual(headers.get('Get'), 'bar');
});

describe('get', function () {
describe('filter', function() {
it('should support RegExp', function () {
Expand Down