Skip to content

Commit 2376eb7

Browse files
jgozmoretalk
authored andcommitted
Set Content-Type in axios
(cherry picked from commit 08d994c)
1 parent 067fd5c commit 2376eb7

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/templates/core/axios/getHeaders.hbs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ async function getHeaders(options: ApiRequestOptions, config: OpenAPIConfig2, fo
2525
const credentials = base64(`${accountSid}:${authToken}`);
2626
headers['Authorization'] = `Basic ${credentials}`;
2727
}
28+
29+
if (options.body) {
30+
if (options.mediaType) {
31+
headers['Content-Type'] = options.mediaType;
32+
} else if (isBlob(options.body)) {
33+
headers['Content-Type'] = options.body.type || 'application/octet-stream';
34+
} else if (isString(options.body)) {
35+
headers['Content-Type'] = 'text/plain';
36+
} else if (!isFormData(options.body)) {
37+
headers['Content-Type'] = 'application/json';
38+
}
39+
}
2840

29-
return headers;
30-
}
41+
return headers;
42+
};

src/templates/core/axios/request.hbs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ import { OpenAPI } from './OpenAPI';
2626
{{>functions/isBlob}}
2727

2828

29+
{{>functions/isFormData}}
30+
31+
2932
{{>functions/isSuccess}}
3033

3134

0 commit comments

Comments
 (0)