BigPizzaV3/CodexPlusPlus · error
Responses 请求体不是 UTF-8:
Error message
Responses 请求体不是 UTF-8:{error} What it means
After decoding an intercepted Responses HTTP request body (per Content-Encoding), the library converts the bytes to a String; if the decoded bytes are not valid UTF-8, this error is raised with the FromUtf8Error details. It is needed because the body must be parsed as UTF-8 text/JSON.
Solutions
- Ensure the client sends Responses bodies encoded as UTF-8 (application/json)
- Check the Content-Encoding header matches the actual compression so decoding is correct
- Inspect the request source for binary or corrupted payloads
- Capture and re-encode the body to valid UTF-8 before processing
Example fix
// before
body bytes: b"\xff\xfe{...}" // invalid UTF-8
// after
String::from_utf8_lossy(&decoded).into_owned() // or send valid UTF-8 JSON Defensive patterns
Strategy: try-catch
Validate before calling
// check the header before decoding
match req.header("content-encoding") {
Some(e) if matches!(e.to_ascii_lowercase().as_str(), "gzip"|"deflate"|"br"|"identity") => {},
other => return reject_unsupported_encoding(other),
} Try / catch
match decode_responses_body(raw, encoding) {
Err(e) if e.to_string().contains("不是 UTF-8") => {
// log a truncated hex dump and return 400 to the client
respond_bad_request("request body must be UTF-8 text");
}
other => other?,
} Prevention
- Send application/json with UTF-8 encoding for Responses requests
- Keep Content-Encoding headers accurate so decoding matches the payload
- Never pipe binary bodies through text-oriented proxy paths
When it happens
Trigger: A Responses request whose body, after gzip/deflate/br decoding, contains invalid UTF-8 — e.g. binary content, a non-UTF-8 charset, or truncated/corrupt compressed data.
Common situations: Proxying a client that sends binary payloads; a server/client mismatch on charset; corrupted middlebox responses; incorrectly labeled encoding causing wrong decompression.
Related errors
AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19).
Data as JSON: /api/errors/3070e7f91636bc65.
Report an issue: GitHub.
Appendix: source
Thrown at crates/codex-plus-core/src/launcher.rs:1453
) -> anyhow::Result<String> {
let encoding = content_encoding.unwrap_or_default().trim();
let decoded = if encoding.is_empty() || encoding.eq_ignore_ascii_case("identity") {
body.to_vec()
} else if encoding.eq_ignore_ascii_case("zstd") {
let decoder = zstd::stream::read::Decoder::new(std::io::Cursor::new(body))?;
let mut limited = decoder.take((MAX_HTTP_BODY_BYTES + 1) as u64);
let mut decoded = Vec::new();
limited.read_to_end(&mut decoded)?;
if decoded.len() > MAX_HTTP_BODY_BYTES {
anyhow::bail!("解压后的请求体超过大小限制");
}
decoded
} else {
anyhow::bail!("不支持的 Content-Encoding:{encoding}");
};
String::from_utf8(decoded)
.map_err(|error| anyhow::anyhow!("Responses 请求体不是 UTF-8:{error}"))
}
fn overlay_image_response() -> (String, Vec<u8>, String, &'static str) {
let not_found = || {
(
"404 Not Found".to_string(),
serde_json::to_vec(&serde_json::json!({
"status": "failed",
"message": "图片覆盖层未启用或图片不可用"
}))
.unwrap_or_default(),
"application/json; charset=utf-8".to_string(),
"helper.overlay_image_not_found",
)
};
let settings = SettingsStore::default().load().unwrap_or_default();
if !settings.codex_app_image_overlay_enabled {
return not_found();View on GitHub (pinned to b1ed92e5e4)