Skip to content

Commit

Permalink
Remove unnecessary checks in default transformRequest
Browse files Browse the repository at this point in the history
`transformRequest` callbacks can always expect their `headers`
parameter to be defined. This is ensured immediately before the callback
is made.
See: https://github.com/axios/axios/blob/1025d1231a7747503188459dd5a6d1effdcea928/lib/core/dispatchRequest.js#L32-L40

Accordingly, checking whether `headers` is `undefined` is unnecessary.

This is related to axios#4201.
  • Loading branch information
brianhelba committed Oct 19, 2021
1 parent 1025d12 commit 164ef22
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/defaults.js
Expand Up @@ -8,8 +8,9 @@ var DEFAULT_CONTENT_TYPE = {
'Content-Type': 'application/x-www-form-urlencoded'
};

function setContentTypeIfUnset(headers, value) {
if (!utils.isUndefined(headers) && utils.isUndefined(headers['Content-Type'])) {
function setContentTypeIfUnset(
, value) {
if (utils.isUndefined(headers['Content-Type'])) {
headers['Content-Type'] = value;
}
}
Expand Down Expand Up @@ -71,7 +72,7 @@ var defaults = {
setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8');
return data.toString();
}
if (utils.isObject(data) || (headers && headers['Content-Type'] === 'application/json')) {
if (utils.isObject(data) || (headers['Content-Type'] === 'application/json')) {
setContentTypeIfUnset(headers, 'application/json');
return stringifySafely(data);
}
Expand Down

0 comments on commit 164ef22

Please sign in to comment.