@@ -207,6 +207,56 @@ describe('requestCompressionHandlerPlugin', () => {
207207 expect ( procedureHandler ) . toHaveBeenCalledWith ( expect . any ( Object ) , '__MOCKED__' )
208208 } )
209209
210+ const binaryContentTypes = [ 'text/csv' , 'application/octet-stream' , undefined ]
211+
212+ it . each ( binaryContentTypes ) (
213+ 'should decode a binary body as a file, content-type: %s' ,
214+ async ( contentType ) => {
215+ const body = compress ( 'a,b\n1,2\n' , 'gzip' )
216+
217+ const { response } = await handler . handle (
218+ new Request ( 'http://localhost' , {
219+ method : 'POST' ,
220+ headers : {
221+ ...( contentType && { 'content-type' : contentType } ) ,
222+ 'content-encoding' : 'gzip' ,
223+ 'content-length' : body . length . toString ( ) ,
224+ } ,
225+ body,
226+ } ) ,
227+ )
228+
229+ expect ( response ?. status ) . toBe ( 200 )
230+ const input = procedureHandler . mock . calls [ 0 ] ! [ 0 ] . input
231+ expect ( input ) . toBeInstanceOf ( File )
232+ expect ( await input . text ( ) ) . toBe ( 'a,b\n1,2\n' )
233+ } ,
234+ )
235+
236+ it . each ( binaryContentTypes ) (
237+ 'should decode a binary body as a file with Node.js adapter, content-type: %s' ,
238+ async ( contentType ) => {
239+ const nodeHandler = new NodeRPCHandler ( procedure , {
240+ plugins : [ new RequestCompressionHandlerPlugin ( ) ] ,
241+ } )
242+
243+ const request = supertest ( ( req : any , res : any ) => {
244+ void nodeHandler . handle ( req , res )
245+ } )
246+ . post ( '/' )
247+ . set ( 'content-encoding' , 'gzip' )
248+
249+ const response = await ( contentType ? request . set ( 'content-type' , contentType ) : request )
250+ . send ( compress ( 'a,b\n1,2\n' , 'gzip' ) )
251+ . buffer ( true )
252+
253+ expect ( response . status ) . toBe ( 200 )
254+ const input = procedureHandler . mock . calls [ 0 ] ! [ 0 ] . input
255+ expect ( input ) . toBeInstanceOf ( File )
256+ expect ( await input . text ( ) ) . toBe ( 'a,b\n1,2\n' )
257+ } ,
258+ )
259+
210260 it ( 'should work with Node.js adapter' , async ( ) => {
211261 const nodeHandler = new NodeRPCHandler ( procedure , {
212262 plugins : [ new RequestCompressionHandlerPlugin ( ) ] ,
0 commit comments