File size: 9,077 Bytes
78e7c43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Input, policy and export contract

Version 0.1.0 · `work:http-range-desk:v1` · Renchao Wu. The pre-implementation [CONTRACT.md](CONTRACT.md) is retained unchanged; this page explains the final implementation interface.

`core.mjs` exports VERSION, IDENTITY, CONTRACT_SHA, parseRequest, parseRange, compareIfRange, makeReport and reportCsv. `parseRange` is the bounded Range helper. `compareIfRange` expects an already validated resource. `makeReport` takes a request and optional Uint8Array, snapshots them and returns a deeply frozen report asynchronously. It performs no HTTP request. The CLI uses the same core; the independent Python reference imports no production parser.

## Request schema

The root has exactly method, base_status, resource, range and if_range. method is the string GET or HEAD. base_status is numeric 200, 304 or 412. A boolean or numeric string is rejected. resource has exactly length, etag, last_modified and date_is_strong.

length is a canonical decimal string: 0 or a nonzero leading digit followed by digits, at most 9223372036854775807. Signs, leading zeros, decimal points and JSON numbers are rejected. etag is null or a valid quoted entity tag, optionally with the case-sensitive W/ prefix. Opaque values accept the declared ASCII/Latin-1 code-point range corresponding to entity-tag octets; JSON text encoding is not an HTTP-header serializer. Backslash is an ordinary opaque character, not a quoted-string escape. etag is capped at 1,024 UTF-16 code units.

last_modified is null or an exact 29-character canonical IMF-fixdate with a valid Gregorian date, matching weekday, GMT, year 1601–9999 and seconds 00–59. Older HTTP date forms and leap seconds are outside this profile. date_is_strong is a boolean assertion supplied by the caller; true requires a known last_modified. The tool does not independently establish validator strength or that the representation exists.

range is null or a header string capped at 8,192 UTF-16 code units. if_range is null or a string capped at 1,024 units. Header CR, LF and NUL are rejected as tool input. Empty strings are present empty values, distinct from absent/null values. parseRequest accepts strict JSON text capped at 65,536 UTF-16 units; the CLI separately caps raw request bytes at 65,536. Extra or missing fields are rejected. The API snapshots JSON-compatible input before computing; the report cannot be changed by subsequent caller mutation.

An optional actual payload is a Uint8Array of at most 1,048,576 bytes. Its observed length must equal the supplied length before any report is emitted, even when Range would be ignored. The API copies those bytes before asynchronous hashes. It does not open a path or upload them. File names and modification times are not included as validator evidence.

## Evaluation order

1. Validate this tool's typed input and optional payload length.
2. A supplied non-200 base_status takes precedence; neither range field is evaluated.
3. HEAD ignores Range and selects no representation body.
4. Absent Range gives a full GET 200 plan and ignores If-Range.
5. Parse the bounded Range. Outside-profile inputs get no predicted status. Unknown units and malformed ranges follow this profile's ignore/full-200 policy.
6. For a complete valid bytes range, evaluate If-Range. A false condition gives full 200; an unsupported date profile gives no predicted status.
7. A zero-length representation uses the declared ignore/full-200 policy while preserving the nonzero suffix's semantic satisfiability.
8. Otherwise, no satisfiable member gives 416; one or more give a 206 plan containing each satisfiable interval in request order.

These are planner choices within a bounded profile, not a promise that all conforming servers take the same permitted path. Authentication, content negotiation, other conditional headers and actual transfer are outside the interface.

## Range parsing and exact arithmetic

The unit is an HTTP token and bytes is case-insensitive. An unknown valid unit is ignored. A malformed unit or multiple equals signs is malformed. Leading/trailing field OWS and SP/HTAB around list members are allowed. Empty list members are retained with their raw ordinals and ignored up to the declared cap; at least one nonempty member is required. Internal spaces around a hyphen are not accepted.

A nonempty member is first-last, first- or -suffix, using ASCII digits. Every numeric component has at most 256 digits, with leading zeros allowed in the header and normalized only in parsed numeric fields. More than 64 nonempty or 64 empty members stops inspection with an outside-profile record; full original text remains in the request. A malformed sibling invalidates the complete Range rather than allowing earlier good parts to leak into a 206 plan. A malformed analysis has no whole-range satisfiable count, although per-member diagnostics remain available.

Offsets are inclusive in HTTP. Intervals also carry exclusive_end and length as exact decimal strings. A nonzero suffix on a zero-length representation has first 0, last null, exclusive_end 0 and length 0 in semantic analysis. Suffix zero is unsatisfiable. Large first positions are safely classified as unsatisfiable; large last positions are clipped to the representation end without Number rounding.

If-Range tags use strong comparison: both must be strong and opaque values must match exactly. Canonical date comparison requires the supplied strong-date assertion and exact timestamp equality. A date later than Last-Modified does not match. Obsolete-looking date forms or the declared unsupported leap-second form produce outside-profile diagnostics. Other invalid validator text produces a nonmatch under the declared policy. An ignored condition is marked not-evaluated rather than fabricated as a match.

## Complete JSON

The report schema is http-range-desk-report-v1. It includes request, provenance, scope, ordered decision_trace, range_analysis, if_range, plan and actual_payload. Provenance hashes the UTF-8 JSON.stringify request snapshot and the frozen contract. It is explicitly not a digest of the original JSON text, external timestamp or authenticity proof.

range_analysis preserves every inspected member's ordinal, exact raw and trimmed text, kind, status, normalized first/last/suffix, satisfiability and resolved interval. complete=false means inspection stopped or was not applicable. Raw-token and inspected-member counts are separate; an unparsed or malformed header does not claim a complete satisfiable count.

plan retains all selected intervals in request order, including duplicates and overlaps. selected_payload_bytes sums their lengths with repetition; unique_payload_bytes measures the merged diagnostic union; overlap_payload_bytes is their difference. The union is diagnostic and does not change selected parts. Each 206 part has a Content-Range; a multipart plan has no top-level Content-Range or invented multipart Content-Length. A single 206 part has a planned length. A 416 plan has bytes */length. Error bodies and actual wire-body lengths are not generated or measured. Zero selected representation bytes do not imply an actual error response has no error body.

With actual bytes, actual_payload includes complete observed-file SHA-256, byte length and one slice record per selected part. Slice hashes cover complete slices; only hexadecimal previews stop after 32 bytes. Without bytes the entire actual_payload is null. Actual-byte hashing does not validate the supplied ETag, HTTP date, content coding or remote representation.

## CSV and browser state

CSV is the selected-interval subset only. All cells are quoted and records end in CRLF. Columns: part_ordinal, member_ordinal, first_inclusive, last_inclusive, exclusive_end, length, content_range, observed_byte_length, sha256, preview_first32_hex. Missing fields are blank, not invented zero offsets or hashes. No selected intervals means a header-only CSV; the full JSON carries diagnostics.

The browser keeps a local file separate from the editable request. Use local file length changes length explicitly; selecting a file alone does not. A mismatch invalidates the report. New edits, file selections, restores and Clear invalidate stale exports. Generation checks discard older asynchronous work. Direct JSON planning works before or after example-inventory failure; late inventory availability must not overwrite a current file binding or report. Filters only alter DOM rows. Clear also removes file input value, bound bytes and every old result table/hash.

## CLI boundary

`node cli.mjs REQUEST.json NEW-REPORT.json [LOCAL-PAYLOAD.bin]` observes regular inputs, refuses final-component symlinks and enforces request/payload byte caps. New output is exclusive wx with mode 0600. Existing output and dangling symlinks are preserved. This is not hostile-filesystem atomicity; a new partially written file can remain after failure. Exit 0 means the local report was written; exit 2 means rejection, usage error or failed I/O, not a verified server response.