Skip to content

Commit

Permalink
Merge pull request #3062 from reduxjs/pr/fBQ-remove-defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Jan 28, 2023
2 parents bd9c4ab + a9abb1d commit 02c2e9b
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions packages/toolkit/src/query/fetchBaseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export type FetchBaseQueryMeta = { request: Request; response?: Response }
* @param {string} jsonContentType Used when automatically setting the content-type header for a request with a jsonifiable body that does not have an explicit content-type header. Defaults to `application/json`.
*
* @param {(this: any, key: string, value: any) => any} jsonReplacer Custom replacer function used when calling `JSON.stringify()`.
*
*
* @param {number} timeout
* A number in milliseconds that represents the maximum time a request can take before timing out.
*/
Expand Down Expand Up @@ -216,9 +216,7 @@ export function fetchBaseQuery({
let meta: FetchBaseQueryMeta | undefined
let {
url,
method = 'GET' as const,
headers = new Headers(baseFetchOptions.headers),
body = undefined,
params = undefined,
responseHandler = 'json' as const,
validateStatus = globalValidateStatus ?? defaultValidateStatus,
Expand All @@ -227,9 +225,7 @@ export function fetchBaseQuery({
} = typeof arg == 'string' ? { url: arg } : arg
let config: RequestInit = {
...baseFetchOptions,
method,
signal,
body,
...rest,
}

Expand All @@ -250,12 +246,12 @@ export function fetchBaseQuery({
Array.isArray(body) ||
typeof body.toJSON === 'function')

if (!config.headers.has('content-type') && isJsonifiable(body)) {
if (!config.headers.has('content-type') && isJsonifiable(config.body)) {
config.headers.set('content-type', jsonContentType)
}

if (isJsonifiable(body) && isJsonContentType(config.headers)) {
config.body = JSON.stringify(body, jsonReplacer)
if (isJsonifiable(config.body) && isJsonContentType(config.headers)) {
config.body = JSON.stringify(config.body, jsonReplacer)
}

if (params) {
Expand Down

0 comments on commit 02c2e9b

Please sign in to comment.