@@ -40,6 +40,8 @@ describe('proxy handler request bodies (#836)', () => {
4040let capturedBody = Buffer . alloc ( 0 )
4141let capturedContentLength : string | undefined
4242let capturedContentType : string | undefined
43+ let capturedFetchBody : BodyInit | null | undefined
44+ let capturedFetchDuplex : 'half' | undefined
4345let capturedUrl = ''
4446let releaseStream : ( ( ) => void ) | undefined
4547const realFetch = globalThis . fetch
@@ -81,6 +83,8 @@ describe('proxy handler request bodies (#836)', () => {
8183const requestUrl = input instanceof Request ? input . url : String ( input )
8284const url = new URL ( requestUrl )
8385if ( url . hostname === 'upstream.test' ) {
86+ capturedFetchBody = init ?. body
87+ capturedFetchDuplex = ( init as RequestInit & { duplex ?: 'half' } | undefined ) ?. duplex
8488const redirected = `http://127.0.0.1:${ upstreamPort } ${ url . pathname } ${ url . search } `
8589return realFetch ( redirected , init )
8690}
@@ -98,6 +102,8 @@ describe('proxy handler request bodies (#836)', () => {
98102capturedBody = Buffer . alloc ( 0 )
99103capturedContentLength = undefined
100104capturedContentType = undefined
105+ capturedFetchBody = undefined
106+ capturedFetchDuplex = undefined
101107capturedUrl = ''
102108releaseStream = undefined
103109} )
@@ -120,10 +126,28 @@ describe('proxy handler request bodies (#836)', () => {
120126} )
121127
122128expect ( response . status ) . toBe ( 200 )
129+ expect ( capturedFetchBody ) . toBeInstanceOf ( ReadableStream )
130+ expect ( capturedFetchDuplex ) . toBe ( 'half' )
123131expect ( capturedBody . equals ( compressed ) ) . toBe ( true )
124132expect ( capturedContentType ) . toBe ( 'text/plain' )
125133} )
126134
135+ it ( 'forwards an explicitly empty opaque POST without a body stream (#853)' , async ( ) => {
136+ const response = await realFetch ( `http://127.0.0.1:${ proxyPort } /_scripts/p/upstream.test/measurement/conversion` , {
137+ method : 'POST' ,
138+ headers : {
139+ 'content-length' : '0' ,
140+ 'content-type' : 'text/plain;charset=UTF-8' ,
141+ } ,
142+ } )
143+
144+ expect ( response . status ) . toBe ( 200 )
145+ expect ( capturedFetchBody ) . toBeUndefined ( )
146+ expect ( capturedFetchDuplex ) . toBeUndefined ( )
147+ expect ( capturedBody ) . toHaveLength ( 0 )
148+ expect ( capturedContentLength ) . toBe ( '0' )
149+ } )
150+
127151it ( 'rejects an allowlisted local network target before the upstream fetch' , async ( ) => {
128152const response = await realFetch ( `http://127.0.0.1:${ proxyPort } /_scripts/p/127.0.0.1/private` )
129153
0 commit comments