mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
## Summary Fixes issue #21677 where `Bun.serve()` was adding redundant Date headers when users provided their own Date header in the response. The root cause was that the HTTP server was writing user-provided Date headers and then µWebSockets was automatically adding its own Date header without checking if one already existed. ## Changes - **Added Date header detection in `NodeHTTP.cpp`**: When a user provides a Date header (either in common or uncommon headers), the code now sets the `HTTP_WROTE_DATE_HEADER` flag to prevent µWebSockets from automatically adding another Date header - **Case-insensitive header matching**: Uses `WTF::equalIgnoringASCIICase` for proper header name comparison in uncommon headers - **Comprehensive test coverage**: Added regression tests that verify no duplicate Date headers in all scenarios (static responses, dynamic responses, proxy responses) ## Test Plan - [x] Added comprehensive regression test in `test/regression/issue/21677.test.ts` - [x] Tests verify only one Date header exists in all response scenarios - [x] Tests fail with current main branch (confirms bug exists) - [x] Tests pass with this fix (confirms bug is resolved) - [x] Existing Date header tests still pass (no regression) ## Testing The reproduction case from the issue now works correctly: **Before (multiple Date headers):** ``` HTTP/1.1 200 OK Date: Thu, 07 Aug 2025 17:02:24 GMT content-type: text/plain;charset=utf-8 Date: Thu, 07 Aug 2025 17:02:23 GMT ``` **After (single Date header):** ``` HTTP/1.1 200 OK Date: Thu, 07 Aug 2025 17:02:23 GMT content-type: text/plain;charset=utf-8 ``` 🤖 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>