11import { FetchResponse } from './fetch_response'
22import { RequestInterceptor } from './request_interceptor'
3- import { getCookie , compact , metaContent } from './lib/utils'
3+ import { getCookie , compact , metaContent , stringEntriesFromFormData , mergeEntries } from './lib/utils'
44
55export class FetchRequest {
66 constructor ( method , url , options = { } ) {
@@ -18,6 +18,7 @@ export class FetchRequest {
1818 } catch ( error ) {
1919 console . error ( error )
2020 }
21+
2122 const response = new FetchResponse ( await window . fetch ( this . url , this . fetchOptions ) )
2223
2324 if ( response . unauthenticated && response . authenticationURL ) {
@@ -97,12 +98,17 @@ export class FetchRequest {
9798 const originalQuery = ( this . originalUrl . split ( '?' ) [ 1 ] || '' ) . split ( '#' ) [ 0 ]
9899 const params = new URLSearchParams ( originalQuery )
99100
100- if ( this . options . query ) {
101- for ( const [ key , value ] of Object . entries ( this . options . query ) ) {
102- params . append ( key , value )
103- }
101+ let requestQuery = this . options . query
102+ if ( requestQuery instanceof window . FormData ) {
103+ requestQuery = stringEntriesFromFormData ( requestQuery )
104+ } else if ( requestQuery instanceof window . URLSearchParams ) {
105+ requestQuery = requestQuery . entries ( )
106+ } else {
107+ requestQuery = Object . entries ( requestQuery || { } )
104108 }
105109
110+ mergeEntries ( params , requestQuery )
111+
106112 const query = params . toString ( )
107113 return ( query . length > 0 ? `?${ query } ` : '' )
108114 }
0 commit comments