New — Iris AI drafts your firewall, routing & rate-limit rules. Explore AI features →
Changelog
Apps

Streams stay live through your traffic rules

On hosted apps, event streams and streamed pages reach visitors part by part while Replace Body, Compress, cache rules and Speed Insights still apply.

Streams stay live through your traffic rules

A hosted app often answers in parts: a live feed sent as server-sent events, a page rendered as it streams, an AI answer word by word. Some traffic rules need the whole answer first, so with such a rule on the endpoint the visitor waited until the app had sent everything.

Now those answers reach the visitor part by part, and the rules still apply. Above, Acme Labs hides its warehouse codes in the live order feed: the Replace Body rule rewrites each event as it arrives, and the feed stays live.

The on_http_response rules of api.example.com: Security headers, Hide warehouse codes in the live feed (Replace body, a regex, on /v1/orders/live) and Brotli / gzip (Compress response)
Replace Body rewrites the live feed event by event; the feed still goes out one event at a time.

What changed

  • Replace Body on an event stream. A server-sent event stream (text/event-stream) is rewritten one event at a time, and each event goes out as soon as it's complete. A match never spans two events, and an event larger than the rule's max_body passes unchanged.
  • Compress while it streams. A response your app sends in parts is compressed as it streams once it passes min_size, and every part still goes out when your app sends it. Event streams are compressed only when the rule's content_types names text/event-stream.
  • Cache rules don't hold what they can't store. A streamed page marked private or no-store, such as a dynamic Next.js page, goes to the visitor as it comes instead of being read to its end first.
  • Incremental: ?1. A response your app marks Incremental: ?1 streams through every rule that doesn't need it whole, and is never cached.
  • Speed Insights on streamed pages. A page your app streams without compressing it gets the Speed Insights collector right after its <head> tag, and keeps streaming.
  • Rules that read the whole answer still do. A Replace Body rule on a streamed answer that isn't an event stream, and an edge function on the response, read the answer to its end first, as before.

Get started

  1. Open an endpoint's Traffic Policy tab and click Add Rule next to on_http_response.
  2. Choose Replace Body, set Find and Replace, and give it a Condition such as req.path == "/v1/orders/live".
  3. Open the stream: each event arrives as your app sends it, rewritten.
  4. Read the docs: Replace Body on event streams and Compress on streamed responses.

Read the docs

Ask an AI to summarise this page
Deploy
App hosting Edge functions Domains & certificates
Connect
Secure tunnels API gateway Multi-region edge
Protect
Bot protection & challenge WAF & firewall Edge login
Observe & AI
Monitoring Inspector & replay Iris AI MCP server AI Gateway
Developers
Developer tools Docs ngrok policy converter Blog Changelog
Compare
Ngris vs ngrok Ngris vs Cloudflare Tunnel Ngris vs Vercel Ngris vs Netlify Expose localhost guide
More
Solutions Pricing Enterprise Sign in Get Started Free