Medlar/Plans/02 Engine/S004-http-core.md
2026-11-25 00:22:51 -06:00

1.9 KiB

S004 — HTTP core with resume and crash-safe files

Category 02 Engine · Model: Opus · Effort: high · Depends on: S002 · Size: L · Human: no Files touched: crates/core/src/{http,disk,part}, crates/core/tests/http

Goal

Download one file over HTTP(S) in a fixed set of ranges, safely. FEATURES 1.1, 1.4, 1.5, 1.7, 1.14.

Read

  • docs/FEATURES.md §1
  • crates/core/src (model, store)
  • testserver README or lib.rs

Steps

  • Choose and pin the HTTP client after checking its docs: HTTP/1.1 forced for segments, Accept-Encoding: identity, redirect control, connect and idle timeouts; record as a decision
  • Probe: size, range support proven by a real 206, validators, name (Content-Disposition with RFC 5987, URL, MIME fallback), final URL
  • Safe names: no path parts, control characters, leading dots, reserved or overlong names; a fuzz-style test
  • Disk writer: free-space check, preallocation with fallback, positioned writes, bounded buffers, fsync policy, .medlar partial file, atomic rename, no silent overwrite
  • Journal of finished ranges that is never ahead of the data on disk; kill -9 test at 50 random moments resumes to an identical file
  • Resume check: validators plus an overlap byte comparison; a changed file stops with its own error
  • Servers with no range, no length, lying length, 200 to a range request, gzip anyway: correct result or a clear error, never a corrupt file
  • HTTP/2 or 3 single-stream path decided by measurement and recorded (1.14)
  • docs/PROGRESS.md entry, tick Plans/INDEX.md, commit S004: …, push

End criteria

  • nice cargo test -j 2 -p medlar-core --test http green, including kill tests
  • SHA-256 equality on every success path

Pitfalls

A 200 at an offset corrupts files. Journal order matters: data, then journal. Never trust Content-Length alone.

Handoff (→ PROGRESS.md)

Part and writer API for S005.