@@ -20,15 +20,12 @@ export const handleFile = (
2020 set . status === 416 )
2121
2222 const defaultHeader = immutable
23- ? ( {
24- 'transfer-encoding' : 'chunked'
25- } as Record < string , string > )
23+ ? { }
2624 : ( {
2725 'accept-ranges' : 'bytes' ,
2826 'content-range' : size
2927 ? `bytes 0-${ size - 1 } /${ size } `
30- : undefined ,
31- 'transfer-encoding' : 'chunked'
28+ : undefined
3229 } as Record < string , string > )
3330
3431 if ( ! set && ! size ) return new Response ( response as Blob )
@@ -147,6 +144,8 @@ type CreateHandlerParameter = {
147144 mapCompactResponse ( response : unknown , request ?: Request ) : Response
148145}
149146
147+ const allowRapidStream = process . env . ELYSIA_RAPID_STREAM === 'true'
148+
150149export const createStreamHandler =
151150 ( { mapResponse, mapCompactResponse } : CreateHandlerParameter ) =>
152151 async (
@@ -207,6 +206,8 @@ export const createStreamHandler =
207206 }
208207 }
209208
209+ const isBrowser = request ?. headers . has ( 'Origin' )
210+
210211 return new Response (
211212 new ReadableStream ( {
212213 async start ( controller ) {
@@ -265,7 +266,7 @@ export const createStreamHandler =
265266 else
266267 controller . enqueue ( format ( chunk . toString ( ) ) )
267268
268- if ( ! isSSE )
269+ if ( ! allowRapidStream && isBrowser && ! isSSE )
269270 /**
270271 * Wait for the next event loop
271272 * otherwise the data will be mixed up
0 commit comments