@@ -4,11 +4,13 @@ import type { IncomingMessage, ServerResponse } from 'node:http'
44import { createServer } from 'node:http'
55import { tmpdir } from 'node:os'
66import path from 'node:path'
7+ import { gzipSync } from 'node:zlib'
78
89import { RPCSerializer } from '@orpc/client'
910import type { Context } from '@orpc/server'
1011import { ORPCError , os } from '@orpc/server'
1112import { RPCHandler } from '@orpc/server/node'
13+ import { RequestCompressionHandlerPlugin } from '@orpc/server/plugins'
1214import type { StandardBodyHint , StandardLazyRequest } from '@standard-server/core'
1315import { generateContentDisposition } from '@standard-server/core'
1416import request from 'supertest'
@@ -599,7 +601,10 @@ describe('tmpFileUploadHandlerPlugin', () => {
599601 method : 'POST' ,
600602 url : '/upload' ,
601603 headers : { } ,
602- resolveBody : async ( ) => resolved as never ,
604+ resolveBody : async ( hint ) => {
605+ expect ( hint ) . toBe ( 'none' )
606+ return resolved as never
607+ } ,
603608 } ,
604609 next : async ( nextOptions ) => {
605610 // A bodiless request resolves to the none hint and stays with the adapter
@@ -1197,6 +1202,30 @@ describe('tmpFileUploadHandlerPlugin', () => {
11971202 expect ( readdirSync ( tmpDir ) ) . toHaveLength ( 0 )
11981203 } )
11991204
1205+ it ( 'leaves compressed bodies it resolves as none unread' , async ( ) => {
1206+ const procedure = vi . fn ( )
1207+ const handler = new RPCHandler ( os . handler ( procedure ) , {
1208+ plugins : [
1209+ new TmpFileUploadHandlerPlugin ( {
1210+ tmpDir,
1211+ maxBodySize : { memory : 1024 , file : 1024 , stream : 1024 } ,
1212+ } ) ,
1213+ new RequestCompressionHandlerPlugin ( ) ,
1214+ ] ,
1215+ } )
1216+
1217+ const res = await request ( ( req : IncomingMessage , res : ServerResponse ) => {
1218+ void handler . handle ( req , res )
1219+ } )
1220+ . post ( '/' )
1221+ . set ( 'content-encoding' , 'gzip' )
1222+ . send ( gzipSync ( Buffer . alloc ( 64 * 1024 , 'a' ) ) )
1223+
1224+ expect ( res . status ) . toBe ( 200 )
1225+ expect ( procedure . mock . calls [ 0 ] ! [ 0 ] . input ) . toBeUndefined ( )
1226+ expect ( readdirSync ( tmpDir ) ) . toHaveLength ( 0 )
1227+ } )
1228+
12001229 it ( 'limits multipart fields and files against their own categories' , async ( ) => {
12011230 const { body, headerSizes, contentSizes } = createMultipartBody ( [
12021231 { header : 'Content-Disposition: form-data; name="first"' , content : 'x' . repeat ( 6 ) } ,
0 commit comments