Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
Update per PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
msutkowski committed Mar 15, 2021
1 parent 5a81294 commit 1265e5f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/fetchBaseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,11 @@ export function fetchBaseQuery({

config.headers = await prepareHeaders(new Headers(stripUndefined(headers)), { getState });

// Only set the content-type to json if there is an object that is not FormData()
if (!config.headers.has('content-type') && body && typeof body === 'object' && typeof body.append !== 'function') {
// Only set the content-type to json if appropriate. Will not be true for FormData, ArrayBuffer, Blob, etc.
const isJsonifiable = (body: any) =>
typeof body === 'object' && (isPlainObject(body) || Array.isArray(body) || typeof body.toJSON === 'function');

if (!config.headers.has('content-type') && isJsonifiable(body)) {
config.headers.set('content-type', 'application/json');
}

Expand Down

0 comments on commit 1265e5f

Please sign in to comment.