File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed
resources/mock-server/src Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -91,14 +91,23 @@ export async function startServer(
9191 return ;
9292 }
9393
94- const data = await response . text ( ) ;
94+ // Handle binary msgpack responses correctly - use arrayBuffer() instead of text()
95+ // to avoid UTF-8 corruption of binary data
96+ const contentType = response . headers . get ( "content-type" ) || "" ;
97+ const isBinary = contentType . includes ( "msgpack" ) || contentType . includes ( "octet-stream" ) ;
98+ const data = isBinary
99+ ? Buffer . from ( await response . arrayBuffer ( ) )
100+ : await response . text ( ) ;
95101
96102 fastify . log . debug ( `[PollyJS] Response status: ${ response . status } ` ) ;
97- fastify . log . debug ( `[PollyJS] Response size: ${ data . length } bytes` ) ;
103+ fastify . log . debug ( `[PollyJS] Response content-type: ${ contentType } ` ) ;
104+ fastify . log . debug ( `[PollyJS] Response is binary: ${ isBinary } ` ) ;
105+ fastify . log . debug ( `[PollyJS] Response size: ${ isBinary ? ( data as Buffer ) . length : ( data as string ) . length } bytes` ) ;
98106
99- // Log response preview (first 200 chars)
100- const preview = data . length > 200 ? data . substring ( 0 , 200 ) + "..." : data ;
101- fastify . log . debug ( `[PollyJS] Response preview: ${ preview } ` ) ;
107+ if ( ! isBinary ) {
108+ const preview = ( data as string ) . length > 200 ? ( data as string ) . substring ( 0 , 200 ) + "..." : data ;
109+ fastify . log . debug ( `[PollyJS] Response preview: ${ preview } ` ) ;
110+ }
102111
103112 reply
104113 . code ( response . status )
You can’t perform that action at this time.
0 commit comments