Downloads for the UK list file: a typed HttpError, text bodies
that survive any content type, HEAD-based change detection (ETag and
Last-Modified), and Range-chunked downloads, since the file is
larger than one response (http.max-response-bytes, 16 MiB by
default).
Values
DEFAULT_CHUNK_BYTES
DEFAULT_CHUNK_BYTES: Int 8388608
USER_AGENT
USER_AGENT: Str "hot-dev-uk-sanctions-pkg/0.1 (+https://hot.dev)"
Functions
body-snippet
fn (body: Any): Str
body-text
fn (response: Any): Str
The response body as text: the decoded string when Hot kept it as one, otherwise the body bytes decoded as UTF-8 (a CSV served as application/octet-stream, or a body that happened to parse as JSON).
byte-ranges
fn (size: Int, chunk: Int): Vec
Split size bytes into inclusive [start, end] ranges of at most chunk bytes (pure). byte-ranges(10, 4) is [[0, 3], [4, 7], [8, 9]].
fetch-ranges
fn (url: Str, ranges: Vec, index: Int, acc: Bytes): Bytes
get-text
fn (url: Str): Map
fn (url: Str, chunk-bytes: Int): Map
GET the list file as text. A response over http.max-response-bytes
is fetched again in Range chunks of chunk-bytes, which the UK
server supports. If it stops supporting them, the Err says to raise
the cap. Returns {text, etag, last-modified}.
head
fn (url: Str): Map
HEAD a list file and return {etag, last-modified, content-length, accept-ranges} (each null when not sent). Refreshes compare these
with the cached version. A conditional GET would save no request: a
changed file over the response cap still needs this HEAD for its size
and Range support.
header
fn (response: Any, name: Str): Str?
A response header by lower-case name, or null.
http-error
fn (response: ::hot::http/HttpResponse, url: Str): HttpError
Build an HttpError from a non-2xx response. Exposed for testing; every request uses it.
is-size-limit-error
fn (result: Result): Bool
True when a request failed because the response exceeded http.max-response-bytes.
request
fn (method: Str, url: Str, headers: Map, body: Any): ::hot::http/HttpResponse
One request with the package User-Agent. Returns the HttpResponse on 2xx, or an Err carrying HttpError (transport failures pass through as their own Err).
too-large-message
fn (url: Str): Str
The error for a file over http.max-response-bytes that can't be fetched in Range chunks. Exposed for testing.
Types
HttpError
HttpError type {
status: Int,
url: Str,
headers: Map,
body: Any,
message: Str
}
A non-2xx response from the UK list server. url is the requested URL (without credentials); message is a one-line summary.