S004: HTTP core with resume and crash-safe files

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-25 00:22:51 -06:00
commit e0ad8d3b73

View file

@ -22,5 +22,16 @@ Verified: `nice cargo test -j 2 -p medlar-testserver` green (44 tests, ~1 s, one
- Proxies: `proxy::Proxy::start_http(auth)` / `start_socks5(auth)`; `seen()` lists kind, target, credentials, allowed; they connect only to loopback or names set with `map_host`.
Not done: BLAKE3 sidecar, HTTP/2, a real gzip body, FTP/SFTP servers (their plans).
## S004 — HTTP core with resume and crash-safe files (2026-11-24)
Done: `core::http` (client, probe, names, fetch, download), `core::disk` (`PartialFile`), `core::part` (`LivePart`, `split`). Choices: D-017 to D-019.
Verified: `nice cargo test -j 2 -p medlar-core` green (47 unit, 16 http, on tmpfs and btrfs); 50 kills at random moments × 4 runs, SHA-256 equal; clippy clean for the new code.
- `http::download(client, store, id, source, options, stop)`: start or continue a task in fixed ranges, returns the finished path. It never sets the task's state. S005 replaces its scheduling; `start`/`resume`/`checkpoint`/`finish` in `download.rs` are the pieces to keep.
- `http::fetch(link, part, file, body, stop)`: one part, one connection. `stop` is a `watch` of bool; stop it, don't drop it (it writes its 512 KiB buffer first). On resume it reloads 4096 bytes and compares. `http::compare` checks any finished range (for S008).
- `LivePart`: `get()`, `remaining()`, `set_end(x)` (false if it would cut bytes written or on their way): a split is `set_end(mid)` on the old part, then a new part `mid..end`.
- `http::probe` gives size, proven ranges, validators, safe name, final link, and the live reply when there are no ranges (pass it to `fetch`, or drop it).
- `disk::PartialFile`: `create` (free name, locked), `reopen`, `reserve`, `write_at`, `read_at`, `sync`, `finish` (never replaces a file). It is `Busy` for a second process.
- `http::Error` has no user text: S007 maps it. `Error::Status` carries Retry-After for S006. Build `Source` with cookies and logins from the keyring; they are dropped on another origin.
Not done: a Content-Length smaller than the real body, on a server without ranges, can't be seen (HTTP ends the body there). A body without any length over plain HTTP can be cut unseen. The power-cut order is by construction, not tested.
## Later
-