From 05bf4baf2b475bb61642ef9df1a567c3bb0e5199 Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Fri, 7 Nov 2025 11:16:54 +0000 Subject: [PATCH] Document that streaming responses are already excluded from compression MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clarified in code comments and documentation that: - Streaming responses (ReadableStream bodies) are rejected from StaticRoute - They throw error at StaticRoute.fromJS():160 requiring buffered body - Streams go through RequestContext, not StaticRoute - Compression only applies to fully buffered static Response objects This answers the "how does streaming work" question - it doesn't go through StaticRoute at all, so compression is never applied to streams. No special handling needed - the architecture naturally prevents it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/bun.js/api/server/StaticRoute.zig | 3 +++ src/http/CompressionConfig.zig | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/bun.js/api/server/StaticRoute.zig b/src/bun.js/api/server/StaticRoute.zig index cfa5cafe21..8948b6e39f 100644 --- a/src/bun.js/api/server/StaticRoute.zig +++ b/src/bun.js/api/server/StaticRoute.zig @@ -249,6 +249,9 @@ pub fn onRequest(this: *StaticRoute, req: *uws.Request, resp: AnyResponse) void } /// Try to serve a compressed variant if compression is enabled and conditions are met +/// +/// NOTE: Streaming responses are NOT handled here - they're rejected at fromJS() line 160 +/// and go through RequestContext instead. This only compresses fully buffered static responses. fn tryServeCompressed(this: *StaticRoute, req: *uws.Request, resp: AnyResponse) bool { const server = this.server orelse return false; const config = server.compressionConfig() orelse return false; diff --git a/src/http/CompressionConfig.zig b/src/http/CompressionConfig.zig index aa7929830b..eb021b81bf 100644 --- a/src/http/CompressionConfig.zig +++ b/src/http/CompressionConfig.zig @@ -24,11 +24,11 @@ pub const COMPRESSION_ENABLED_BY_DEFAULT = false; /// - Only caches variants that clients actually request (lazy) /// - Compression often makes files smaller, but we store BOTH original and compressed /// -/// ## Not Supported (Yet): -/// - Dynamic routes (would need LRU cache with TTL and size limits) -/// - Streaming responses -/// - Cache eviction or memory limits -/// - Selective caching per-route +/// ## Not Supported: +/// - **Dynamic routes** - Responses from fetch() handlers (would need LRU cache with TTL) +/// - **Streaming responses** - ReadableStream bodies are rejected from static routes (see StaticRoute.zig:160) +/// - **Cache eviction** - No memory limits or LRU eviction +/// - **Per-route control** - Can only enable/disable globally or per-algorithm /// /// ## Usage: /// ```js