2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-11 18:02:32 +03:00

fix: handling of array values for AxiosHeaders (#5085)

Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
Dmitriy Mozgovoy
2022-10-13 22:11:01 +03:00
committed by GitHub
parent 85740c3e7a
commit 110ae9ae61
4 changed files with 45 additions and 11 deletions
+4 -10
View File
@@ -15,7 +15,7 @@ function normalizeValue(value) {
return value;
}
return String(value);
return utils.isArray(value) ? value.map(normalizeValue) : String(value);
}
function parseTokens(str) {
@@ -102,13 +102,7 @@ Object.assign(AxiosHeaders.prototype, {
return;
}
if (utils.isArray(_value)) {
_value = _value.map(normalizeValue);
} else {
_value = normalizeValue(_value);
}
self[key || _header] = _value;
self[key || _header] = normalizeValue(_value);
}
if (utils.isPlainObject(header)) {
@@ -222,13 +216,13 @@ Object.assign(AxiosHeaders.prototype, {
return this;
},
toJSON: function() {
toJSON: function(asStrings) {
const obj = Object.create(null);
utils.forEach(Object.assign({}, this[$defaults] || null, this),
(value, header) => {
if (value == null || value === false) return;
obj[header] = utils.isArray(value) ? value.join(', ') : value;
obj[header] = asStrings && utils.isArray(value) ? value.join(', ') : value;
});
return obj;