Using Server Sent Events (SSE) with Cloudflare Proxy

I have my site proxied via the Cloudflare DNS proxy. I have and endpoint on my site that feeds a stream of Server Sent Events to the client. It appears that Cloudflares proxy is interfering with that, since the client never receives any events when accessing the web server via Cloudflare proxy.

I’ve searched around a little and it appears the issue is caused by the Cloudflare proxy buffering the response and never flushing it. The commonly recommended way to solve the issue is to set Caching to bypass via Page Rules.

I’ve done this, but even after waiting several hours for the change to propagate I am still not receiving any events. I’ve created another rule using the Rules Engine Cache rules, but the issue remains. The URI based rules do not seem to work as expected.

Couple of questions:

  1. How can I configure Cloudflare proxy so my SSE make it to the client?
  2. Is there a way to verify that the Page/Cache rules get triggered correctly? I’ve triple checked the configuration, but I suspect I am not actually hitting the rules correctly and my request still get proxied.

Thanks!

I believe I have figured it out. To prevent my locally hosted nginx from buffering the response I had to add a X-Accel-Buffering: no response header on my application server. I figured what are the chances that Cloudflare is using nginx and I can disable response buffering using the same header

I changed my local nginx configuration to add the X-Accel-Buffering: no response header when it gets a request from Cloudflare on the SSE URI and voila, it now works!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.