ContentRange

is a Content-Range header value in the bytes unit (RFC 9110 §14.4): the inclusive range of positions the content covers — Nothing in the bytes */1234 form a 416 answers with — and the complete length of the representation, Nothing when the sender did not know it (bytes 0-499/*).

bytes

defn

(Fn [Long, Long, Long] String)

                        (bytes lo hi complete)
                    

formats the Content-Range of a 206 response whose content covers the inclusive positions lo to hi of a representation of complete bytes, e.g. bytes 0-499/1234.

complete

instantiate

(Fn [(Ref ContentRange a)] (Ref (Maybe Long) a))

gets the complete property of a ContentRange.

copy

instantiate

(Fn [(Ref ContentRange a)] ContentRange)

copies a ContentRange.

delete

instantiate

(Fn [ContentRange] ())

deletes a ContentRange. Should usually not be called manually.

init

instantiate

(Fn [(Maybe (Pair Long Long)), (Maybe Long)] ContentRange)

creates a ContentRange.

parse

defn

(Fn [(Ref String a)] (Result ContentRange String))

                        (parse s)
                    

parses a received Content-Range header value (RFC 9110 §14.4) as (Result ContentRange String).

All three forms a bytes response may carry are understood: bytes 0-499/1234, bytes 0-499/* for a complete length the sender did not know, and bytes */1234 for the unsatisfied form of a 416. Unit names are compared case-insensitively. Any other unit fails, as does the bytes */* form, which the grammar has no room for.

The two clauses of §14.4's validity rule are both enforced: a last-pos below its first-pos fails, and so does a known complete-length at or below the last-pos it is paired with — bytes 0-1234/1234 is an error, not a range. A * complete length is exempt, having nothing to contradict.

prn

instantiate

(Fn [(Ref ContentRange a)] String)

converts a ContentRange to a string.

range

instantiate

(Fn [(Ref ContentRange a)] (Ref (Maybe (Pair Long Long)) a))

gets the range property of a ContentRange.

satisfied?

defn

(Fn [(Ref ContentRange a)] Bool)

                        (satisfied? cr)
                    

whether the value names a range of positions, rather than being the bytes */1234 form of a 416.

set-complete

instantiate

(Fn [ContentRange, (Maybe Long)] ContentRange)

sets the complete property of a ContentRange.

set-complete!

instantiate

(Fn [(Ref ContentRange a), (Maybe Long)] ())

sets the complete property of a ContentRange in place.

set-range

instantiate

(Fn [ContentRange, (Maybe (Pair Long Long))] ContentRange)

sets the range property of a ContentRange.

set-range!

instantiate

(Fn [(Ref ContentRange a), (Maybe (Pair Long Long))] ())

sets the range property of a ContentRange in place.

str

defn

(Fn [(Ref ContentRange a)] String)

                        (str cr)
                    

serializes back into a header value. Anything parse produced reads back into an equal ContentRange; a hand-built value §14.4 has no room for — both fields Nothing, or a complete at or below the range's last-pos — writes a header value parse rejects.

unsatisfied

defn

(Fn [Long] String)

                        (unsatisfied complete)
                    

formats the bytes */1234 Content-Range of a 416 response, naming the complete length of the representation.

update-complete

instantiate

(Fn [ContentRange, (Ref (Fn [(Maybe Long)] (Maybe Long) a) b)] ContentRange)

updates the complete property of a ContentRange using a function f.

update-range

instantiate

(Fn [ContentRange, (Ref (Fn [(Maybe (Pair Long Long))] (Maybe (Pair Long Long)) a) b)] ContentRange)

updates the range property of a ContentRange using a function f.