Skip to content

Stream DirectoryHTTPHandler responses via HTTPBodySequence(file:)#213

Merged
swhitty merged 2 commits into
swhitty:mainfrom
ianegordon:ian/tvt-286-directoryhttphandler-loads-entire-file-into-memory-no
May 16, 2026
Merged

Stream DirectoryHTTPHandler responses via HTTPBodySequence(file:)#213
swhitty merged 2 commits into
swhitty:mainfrom
ianegordon:ian/tvt-286-directoryhttphandler-loads-entire-file-into-memory-no

Conversation

@ianegordon

Copy link
Copy Markdown
Contributor

Summary

  • DirectoryHTTPHandler now streams responses via HTTPBodySequence(file:) instead of Data(contentsOf:), matching FileHTTPHandler. Multi-gigabyte assets no longer load fully into memory per request.
  • Existence-check folds into the HTTPBodySequence(file:) throw, mirroring FileHTTPHandler's do/catch → 404 pattern (no TOCTOU window).
  • Built on TVT-290's (mtime, size) ETag — that change removed the last reason DirectoryHTTPHandler needed Data in scope.

Closes TVT-286.

Test plan

  • New directoryHandler_streamsBody_fromFile test asserts response.payload's body sequence is an AsyncBufferedFileSequence (was AsyncBufferedCollection<Data> before this change). Confirmed failing on main, passing after the fix.
  • Existing 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

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

codecov Bot commented Apr 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.80%. Comparing base (05b6b66) to head (31e74af).

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.
📢 Have feedback on the report? Share it here.

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 swhitty merged commit 1369671 into swhitty:main May 16, 2026
11 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants