Skip to content
Kerem Atam

Bug Chronicles #1: chat streaming that broke behind Cloudflare

If your chat app’s streaming breaks in prod behind Cloudflare, set Cache-Control: no-transform.

Apparently, Cloudflare is trying to process (and compress) the response if you don’t.

import { middleware } from "../trpc";

export const withStreamingHeaders = middleware(async ({ ctx, next }) => {
  // Prevent intermediaries from altering/buffering streaming responses
  ctx.honoContext.header("Cache-Control", "no-transform");
  // If running behind Nginx, this disables proxy buffering per response
  ctx.honoContext.header("X-Accel-Buffering", "no");
  return next();
});

Validate the issue

Copy your request as curl and add -H "Accept-Encoding: identity". If it works, you’ve got the same problem.

Caveat: for some reason, Chrome no longer includes cookies when copying as curl, but Firefox still does.

Firefox network panel with the context menu open on a request. Under Copy Value, the menu offers Copy as cURL.

The copied curl command for a POST request, with the header Accept-Encoding: identity added right after curl and marked with a red box.

This post started as a thread on X.



Comments

Comments are kept in GitHub Discussions. You need a GitHub account to write one.


Previous Post
Duplicate IP Detection in Network
Next Post
Bug Chronicles #2: how I caused hundreds of double payments