@@ -72,10 +72,14 @@ function getQuery(
7272 return queryString ( queryObj )
7373}
7474
75- function getHeaders ( body ?: string , init ?: HeadersInit ) {
75+ function getHeaders ( body ?: CustomRequestInit [ 'body' ] , init ?: HeadersInit ) {
7676 const headers = new Headers ( init )
7777
78- if ( body !== undefined && ! headers . has ( 'Content-Type' ) ) {
78+ if (
79+ body !== undefined &&
80+ ! ( body instanceof FormData ) &&
81+ ! headers . has ( 'Content-Type' )
82+ ) {
7983 headers . append ( 'Content-Type' , 'application/json' )
8084 }
8185
@@ -86,8 +90,11 @@ function getHeaders(body?: string, init?: HeadersInit) {
8690 return headers
8791}
8892
89- function getBody ( method : Method , payload : any ) {
90- const body = sendBody ( method ) ? JSON . stringify ( payload ) : undefined
93+ function getBody ( method : Method , payload : unknown ) : CustomRequestInit [ 'body' ] {
94+ if ( ! sendBody ( method ) ) {
95+ return
96+ }
97+ const body = payload instanceof FormData ? payload : JSON . stringify ( payload )
9198 // if delete don't send body if empty
9299 return method === 'delete' && body === '{}' ? undefined : body
93100}
@@ -108,7 +115,10 @@ function mergeRequestInit(
108115 return { ...first , ...second , headers }
109116}
110117
111- function getFetchParams ( request : Request ) {
118+ function getFetchParams ( request : Request ) : {
119+ url : string
120+ init : CustomRequestInit
121+ } {
112122 // clone payload
113123 // if body is a top level array [ 'a', 'b', param: value ] with param values
114124 // using spread [ ...payload ] returns [ 'a', 'b' ] and skips custom keys
0 commit comments