Downloads for the EU list file: a typed HttpError, text bodies
that survive any content type, HEAD-based change detection, and a
clear error for a file over http.max-response-bytes.
Values
USER_AGENT
USER_AGENT: Str "hot-dev-eu-sanctions-pkg/0.1 (+https://hot.dev)"
Functions
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).
Example
::eu::sanctions::http/body-text({body: "<export/>"}) // "<export/>"
::eu::sanctions::http/body-text({}) // ""
get-text
fn (url: Str, needed-bytes: Int): Str
GET the list file as text: the body as a Str, or an Err. A response over
http.max-response-bytes is an Err saying to raise the cap to
needed-bytes. The server ignores Range requests, so a chunked download
can't help.
Example
// Needs http.max-response-bytes raised to at least 32 MiB
xml ::eu::sanctions::http/get-text("https://webgate.ec.europa.eu/fsd/fsf/public/files/xmlFullSanctionsList_1_1/content?token=dG9rZW4tMjAxNw", 33554432)
length(::eu::sanctions::xml/records(xml, "sanctionEntity"))
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.
Example
info ::eu::sanctions::http/head("https://webgate.ec.europa.eu/fsd/fsf/public/files/xmlFullSanctionsList_1_1/content?token=dG9rZW4tMjAxNw")
info.last-modified
info.content-length
header
fn (response: Any, name: Str): Str?
A response header by lower-case name, or null.
Example
::eu::sanctions::http/header({headers: {etag: "abc"}}, "etag") // "abc"
::eu::sanctions::http/header({headers: {}}, "etag") // 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.
Example
response {status: 503, headers: {}, body: "down"}
e ::eu::sanctions::http/http-error(response, "https://example.com/list.xml")
e.status // 503
e.message // "HTTP 503 from https://example.com/list.xml: down"
is-size-limit-error
fn (result: Result): Bool
True when a request failed because the response exceeded
http.max-response-bytes.
Example
::eu::sanctions::http/is-size-limit-error(err("response exceeds http.max-response-bytes")) // true
::eu::sanctions::http/is-size-limit-error(err("connection refused")) // false
::eu::sanctions::http/is-size-limit-error("<export/>") // false
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).
Example
url "https://webgate.ec.europa.eu/fsd/fsf/public/files/xmlFullSanctionsList_1_1/content?token=dG9rZW4tMjAxNw"
response ::eu::sanctions::http/request("HEAD", url, {}, "")
::eu::sanctions::http/header(response, "last-modified")
too-large-message
fn (url: Str, needed-bytes: Int): Str
The error for a file over http.max-response-bytes, saying how far to
raise it. Exposed for testing.
Example
msg ::eu::sanctions::http/too-large-message("https://example.com/list.xml", 33554432)
contains(msg, "to at least 33554432 (32 MiB)") // true
Types
HttpError
HttpError type {
status: Int,
url: Str,
headers: Map,
body: Any,
message: Str
}
A non-2xx response from the EU list server. url is the requested URL (without credentials); message is a one-line summary.