Fix formatting of headers in request operation (#13759)

Fixes #13737
This commit is contained in:
Rijk van Zanten
2022-06-06 16:02:47 -04:00
committed by GitHub
parent 7bb9edbcd6
commit d1b7d3e666

View File

@@ -5,14 +5,19 @@ type Options = {
url: string;
method: Method;
body: Record<string, any> | string | null;
headers: Record<string, string>;
headers?: { header: string; value: string }[] | null;
};
export default defineOperationApi<Options>({
id: 'request',
handler: async ({ url, method, body, headers }) => {
const result = await axios({ url, method, data: body, headers });
const customHeaders = headers?.reduce((acc, { header, value }) => {
acc[header] = value;
return acc;
}, {} as Record<string, string>);
const result = await axios({ url, method, data: body, headers: customHeaders });
return { status: result.status, statusText: result.statusText, headers: result.headers, data: result.data };
},