mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
## Summary Fixes https://github.com/oven-sh/bun/issues/19198 This implements RFC 9110 Section 13.1.2 If-None-Match conditional request support for static routes in Bun.serve(). **Key Features:** - Automatic ETag generation for static content based on content hash - If-None-Match header evaluation with weak entity tag comparison - 304 Not Modified responses for cache efficiency - Standards-compliant handling of wildcards (*), multiple ETags, and weak ETags (W/) - Method-specific application (GET/HEAD only) with proper 405 responses for other methods ## Implementation Details - ETags are generated using `bun.hash()` and formatted as strong ETags (e.g., "abc123") - Preserves existing ETag headers from Response objects - Uses weak comparison semantics as defined in RFC 9110 Section 8.8.3.2 - Handles comma-separated ETag lists and malformed headers gracefully - Only applies to GET/HEAD requests with 200 status codes ## Files Changed - `src/bun.js/api/server/StaticRoute.zig` - Core implementation (~100 lines) - `test/js/bun/http/serve-if-none-match.test.ts` - Comprehensive test suite (17 tests) ## Test Results - ✅ All 17 new If-None-Match tests pass - ✅ All 34 existing static route tests pass (no regressions) - ✅ Debug build compiles successfully ## Test plan - [ ] Run existing HTTP server tests to ensure no regressions - [ ] Test ETag generation for various content types - [ ] Verify 304 responses reduce bandwidth in real scenarios - [ ] Test edge cases like malformed If-None-Match headers 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>