Stream DirectoryHTTPHandler responses via HTTPBodySequence(file:)#213
Merged
swhitty merged 2 commits intoMay 16, 2026
Conversation
Matches FileHTTPHandler so a multi-gigabyte asset under a directory handler no longer loads fully into memory per request. Existence-check moves into the HTTPBodySequence(file:) throw, mirroring FileHTTPHandler's do/catch → 404 pattern. Closes TVT-286 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #213 +/- ##
==========================================
+ Coverage 92.77% 92.80% +0.02%
==========================================
Files 70 70
Lines 3653 3654 +1
==========================================
+ Hits 3389 3391 +2
+ Misses 264 263 -1 ☔ View full report in Codecov by Sentry. |
Adds tests for Cache-Control/Date/Last-Modified/ETag header emission on 200 responses, plus 304 round-trips and 200 fallthrough for both If-Modified-Since and If-None-Match. Exercises lines in DirectoryHTTPHandler.handleRequest that previously had no coverage. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
swhitty
approved these changes
May 16, 2026
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
DirectoryHTTPHandlernow streams responses viaHTTPBodySequence(file:)instead ofData(contentsOf:), matchingFileHTTPHandler. Multi-gigabyte assets no longer load fully into memory per request.HTTPBodySequence(file:)throw, mirroringFileHTTPHandler'sdo/catch → 404pattern (no TOCTOU window).(mtime, size)ETag — that change removed the last reasonDirectoryHTTPHandlerneededDatain scope.Closes TVT-286.
Test plan
directoryHandler_streamsBody_fromFiletest assertsresponse.payload's body sequence is anAsyncBufferedFileSequence(wasAsyncBufferedCollection<Data>before this change). Confirmed failing onmain, passing after the fix.DirectoryHTTPHandlerTests(file content, content-type, 404, sub-directory, server-path matching) all still pass.swift test— 440 tests pass.swift build— clean, no warnings.🤖 Generated with Claude Code