Emit a Date header on all responses (RFC 9110 §6.6.1) - #231
Merged
swhitty merged 2 commits intoJul 28, 2026
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #231 +/- ##
==========================================
+ Coverage 92.83% 92.87% +0.03%
==========================================
Files 71 72 +1
Lines 3743 3748 +5
==========================================
+ Hits 3475 3481 +6
+ Misses 268 267 -1 ☔ View full report in Codecov by Harness. |
RFC 9110 §5.6.7 requires a two-digit day (day = 2DIGIT) and the literal "GMT"; the previous pattern "EEE, d MMM yyyy HH:mm:ss zzz" emitted single-digit days and relied on locale behaviour for the zone name. HTTPDate is now the single source of truth for HTTP date formatting (TVT-294). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
RFC 9110 §6.6.1: an origin server with a clock MUST generate a Date header field in all 2xx, 3xx and 4xx responses and MAY in 1xx/5xx. HTTPConnection.sendResponse now injects an IMF-fixdate Date when the response does not already carry one; handler-supplied values are preserved. Covers framework-authored responses (404 unhandled, 500 handler-throw, timeout) that never run user code (TVT-1057). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ianegordon
force-pushed
the
ian/tvt-1057-emit-a-date-header-on-all-responses-rfc-9110-661-must
branch
from
July 23, 2026 16:42
5d61306 to
5b3298d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two related conformance fixes for HTTP date handling:
IMF-fixdate formatting — HTTP dates are now formatted per RFC 9110 §5.6.7 via a new shared
HTTPDateformatter: pattern"EEE, dd MMM yyyy HH:mm:ss 'GMT'". The previous pattern ("EEE, d MMM yyyy HH:mm:ss zzz") emitted single-digit days, violating the ABNF (day = 2DIGIT), and relied on locale behaviour for the zone name instead of the literalGMT.HTTPCacheControland the file/directory handlers now share this single formatter.Dateheader on every response — RFC 9110 §6.6.1: "An origin server with a clock … MUST generate a Date header field in all 2xx (Successful), 3xx (Redirection), and 4xx (Client Error) responses, and MAY generate a Date header field in 1xx (Informational) and 5xx (Server Error) responses."HTTPConnection.sendResponsenow injects an IMF-fixdateDatewhen the response doesn't already carry one (unconditionally across status classes — conformant and simpler). Handler-suppliedDatevalues are never overwritten. SincesendResponseis the single server egress, framework-authored responses (404 unhandled, 500 handler-throw, timeout) are covered without running user code.Tests
All 456 package tests pass.
HTTPDateTests: exact output for both RFC example dates ("Sun, 06 Nov 1994 08:49:37 GMT", "Tue, 15 Nov 1994 08:12:31 GMT"), zero-padded-day case, format→parse round-trip.HTTPConnectionTests: generated well-formedDateon a 200; byte-exact test proving a suppliedDateis preserved verbatim.HTTPServerTests: wire-level assertions that 404-unhandled, 500-handler-throw, and timeout responses carry a well-formed IMF-fixdateDate.Notes
DateFormatterthread safety is documented for Apple platforms (iOS 7+/macOS 10.9+); swift-corelibs-foundation documents no equivalent guarantee. The shared-static-formatter pattern already existed inHTTPCacheControl; this PR extends its use to every response.🤖 Generated with Claude Code