HTTP resume and If-Range / 断点续传与 If-Range / ダウンロード再開と If-Range Article and experiment date: 2026-10-28 Files http-resume-if-range-lab.py Complete loopback server and clients http-resume-if-range-results.json Actual recorded output http-resume-if-range-README.txt This file Run from the extracted directory python3 http-resume-if-range-lab.py > rerun.json Requirements and recorded environment Python standard library, curl executable on PATH, permission to bind a local loopback socket. No Internet service, credentials or package installation. macOS 27.0.1, arm64, CPython 3.12.14, curl 8.7.1. The recorded curl version banner reports its own x86_64 build target; the machine/Python architecture is arm64. The full actual banner is in the JSON. Other versions may give different stderr text or environment values. What actually runs A hand-written BaseHTTPRequestHandler listens only on 127.0.0.1, an OS-assigned temporary port, one path /asset, HTTP/1.0 responses. Sequential requests switch that SAME path between declared immutable fixtures, with distinct strong tags. This is not SimpleHTTPRequestHandler's built-in/default range behavior. All requests use Accept-Encoding: identity. Python ignores configured proxies; curl uses -q to skip curlrc and --noproxy '*' for the loopback request. Eleven urllib requests and two curl resume requests are recorded, thirteen server exchanges total. Request/response fields and exact body hex are kept. Dynamic URLs are redacted as in recorded curl argument lists; the runnable script supplies the actual assigned URL, not a placeholder. The server is shut down and joined, and temporary curl files removed at end. Fixtures and assertions A: 48 bytes, ETag "rev-a", starts with version-A|. B: 48 DIFFERENT bytes, ETag "rev-b", starts with version-B|. Empty: zero bytes, ETag "rev-empty". UTF-8: the two characters 谷米 plus newline, seven bytes, ETag "rev-utf8". Fixed payloads are embedded in the script and included as hex in the output. First request gets full A, then bytes=0-9 fetches ten bytes of A. Same A + bytes=10- + If-Range "rev-a": 206, bytes 10-47/48, 38 bytes; concatenation is byte-for-byte A and its SHA-256 matches. Changed B without If-Range: 206; A prefix + B tail is length 48, but neither A nor B, with a different SHA-256. This is an intentionally wrong client action. Changed B with If-Range "rev-a": 200, full B; replacement equals B, while naive append gives 58 bytes. A separate ignore-Range branch also returns 200. bytes=-5 -> bytes 43-47/48; bytes=44-999 -> bytes 44-47/48. bytes=48- -> 416, bytes */48. That offset is taken from the incorrect hybrid's length, demonstrating that an out-of-bounds response cannot certify the copy. Empty + bytes=0- -> 416, bytes */0 (the teaching server's chosen behavior). UTF-8 + bytes=0-0 -> 206, one byte e8; decoding that byte alone is rejected. curl --continue-at - with the old strong tag resumes unchanged A (exit 0, output 48 bytes). With current B, this run exits 33 and leaves the old ten-byte partial file unchanged. The script checks rejection and unchanged bytes; the actual exit number and stderr are recorded, not assumed for all curl versions. Interpretation and boundaries Prefixes are prepared deliberately, including the curl temporary files. All HTTP requests are real; no actual cable loss, interrupted transport, process crash, disk corruption, atomic replacement or recovery test was run. One byte range and fixed identity-coded representations only. Unsupported or malformed range syntax is ignored by this small handler; it is not a complete HTTP implementation. No multipart ranges, HTTP-date If-Range, gzip, TLS, redirects, browser, CDN/proxy, concurrency or throughput testing. Strong tags name known fixed payloads; they are not presented as checksums. SHA-256 in this lab is a separate local comparison of exact bytes. Primary/official sources read 2026-10-28 RFC 9110 section 13.1.5, normative If-Range behavior and strong comparison https://www.rfc-editor.org/rfc/rfc9110.html#section-13.1.5 MDN official HTTP documentation: Range, byte units and encoded representations https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Range Content-Range fields https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Range If-Range https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/If-Range ETag as a version identifier https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/ETag Range response overview https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Range_requests 416 https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/416 curl --continue-at https://curl.se/docs/manpage.html#-C libcurl range error (33) https://curl.se/libcurl/c/libcurl-errors.html Python HTTPServer and BaseHTTPRequestHandler https://docs.python.org/3.12/library/http.server.html