@@ -72,10 +72,14 @@ function getQuery(
72
72
return queryString ( queryObj )
73
73
}
74
74
75
- function getHeaders ( body ?: string , init ?: HeadersInit ) {
75
+ function getHeaders ( body ?: CustomRequestInit [ 'body' ] , init ?: HeadersInit ) {
76
76
const headers = new Headers ( init )
77
77
78
- if ( body !== undefined && ! headers . has ( 'Content-Type' ) ) {
78
+ if (
79
+ body !== undefined &&
80
+ ! ( body instanceof FormData ) &&
81
+ ! headers . has ( 'Content-Type' )
82
+ ) {
79
83
headers . append ( 'Content-Type' , 'application/json' )
80
84
}
81
85
@@ -86,8 +90,11 @@ function getHeaders(body?: string, init?: HeadersInit) {
86
90
return headers
87
91
}
88
92
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 )
91
98
// if delete don't send body if empty
92
99
return method === 'delete' && body === '{}' ? undefined : body
93
100
}
@@ -108,7 +115,10 @@ function mergeRequestInit(
108
115
return { ...first , ...second , headers }
109
116
}
110
117
111
- function getFetchParams ( request : Request ) {
118
+ function getFetchParams ( request : Request ) : {
119
+ url : string
120
+ init : CustomRequestInit
121
+ } {
112
122
// clone payload
113
123
// if body is a top level array [ 'a', 'b', param: value ] with param values
114
124
// using spread [ ...payload ] returns [ 'a', 'b' ] and skips custom keys
0 commit comments