Character encoding is decided by this chain (§31.7):
Usage
zu_resp_text(resp, encoding = NULL, on_invalid = c("error", "substitute"))Details
encodingif you pass one;the
charsetparameter ofContent-Type, ificonv()knows it;a UTF-8, UTF-16LE or UTF-16BE byte-order mark, which is then stripped;
otherwise UTF-8 — not the ISO-8859-1 that RFC 7231 nominally implies. That default is a historical artefact; UTF-8 is right far more often, and being wrong the other way produces mojibake users blame on the server.
For application/json, RFC 8259 mandates UTF-8, so steps 2–4 are skipped.
The result is always marked UTF-8.
Examples
zu_resp_text(zu_response(200L, c("Content-Type" = "text/plain"), "hi"))
#> [1] "hi"