File tree Expand file tree Collapse file tree 3 files changed +23
-0
lines changed
Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " plantae " : patch
3+ ---
4+
5+ fix: handle array buffer on axios adapter
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import type {
77
88import createMiddleware from "../createMiddleware" ;
99import type { AdapterRequest , AdapterResponse , Plugin } from "../types" ;
10+ import { isArrayBuffer } from "../utils" ;
1011
1112type Interceptor < T extends keyof AxiosInstance [ "interceptors" ] > = Parameters <
1213 AxiosInstance [ "interceptors" ] [ T ] [ "use" ]
@@ -109,6 +110,10 @@ async function extendClientRequest(
109110function convertToAdapterResponse ( res : AxiosResponse ) : AdapterResponse {
110111 const headers = res . headers as AxiosResponseHeaders ;
111112
113+ if ( ! res . config . responseType && isArrayBuffer ( res . data ) ) {
114+ res . config . responseType = "arraybuffer" ;
115+ }
116+
112117 return new Response (
113118 res . data !== null &&
114119 typeof res . data === "object" &&
@@ -149,6 +154,8 @@ async function extendClientResponse(
149154 headers . set ( "Content-Type" , "application/json" ) ;
150155 }
151156 } catch { }
157+ } else if ( clientResponse . config . responseType === "arraybuffer" ) {
158+ data = await adapterResponse . arrayBuffer ( ) ;
152159 } else {
153160 data = await adapterResponse . blob ( ) ;
154161 }
Original file line number Diff line number Diff line change 1+ const kindOf = ( ( cache ) => ( thing : any ) => {
2+ const str = toString . call ( thing ) ;
3+ return cache [ str ] || ( cache [ str ] = str . slice ( 8 , - 1 ) . toLowerCase ( ) ) ;
4+ } ) ( Object . create ( null ) ) ;
5+
6+ const kindOfTest = ( type : string ) => {
7+ type = type . toLowerCase ( ) ;
8+ return ( thing : any ) => kindOf ( thing ) === type ;
9+ } ;
10+
11+ export const isArrayBuffer = kindOfTest ( "ArrayBuffer" ) ;
You can’t perform that action at this time.
0 commit comments