How to disable cloudflare proxy buffering?

I have a simple service worker where I’m trying to receive uploaded data and calculate received chunk size in real time.

The problem is that - it looks like CF has some buffering before data comes to request handler or in other words - I think CF grabs the whole brody request before transfering it to service worker.

I checked timestamp at the beginning of the request on frontend side and I compared it with timestamp in service worker (at the beginning of request handler) and I can see delay ~5s for 20-25Mb data size. So, it looks like request handler comes into the game only when the whole file is uploaded to CF. Am I right?

There is an option to disable it in nginx, but is it possible to disable it in CF? Module ngx_http_proxy_module

Here is my service worker example.

addEventListener('fetch', event => {
    event.respondWith(fetchAndApply(event))
})

async function fetchAndApply(event) {
    var headers = new Headers();
    headers.append('Cache-Control', 'no-cache');
    headers.append('Access-Control-Allow-Origin', '*');
    headers.append('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');

    var init = { "status": 200, "statusText": "ok", "headers": headers };
    return new Response(Date.now(), init);
}

I am also running into this same problem. I use Apache commons file-upload and track the upload progress. This breaks this system as everything stalls while CF receives the data.

How can I disable this?

I’ve come across this as well. Setting SSE header seems to fix buffering issue for me:

'Content-Type': 'text/event-stream', when using TypeScript’s new Response(new ReadableStream()).

worth noting, I’m sure cloudflare tunnels.