{"record":{"id":"3070e7f91636bc65","repo":"BigPizzaV3/CodexPlusPlus","slug":"responses-utf-8-error","errorCode":null,"errorMessage":"Responses 请求体不是 UTF-8：{error}","messagePattern":"Responses 请求体不是 UTF-8：(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/launcher.rs","lineNumber":1453,"sourceCode":") -> anyhow::Result<String> {\n    let encoding = content_encoding.unwrap_or_default().trim();\n    let decoded = if encoding.is_empty() || encoding.eq_ignore_ascii_case(\"identity\") {\n        body.to_vec()\n    } else if encoding.eq_ignore_ascii_case(\"zstd\") {\n        let decoder = zstd::stream::read::Decoder::new(std::io::Cursor::new(body))?;\n        let mut limited = decoder.take((MAX_HTTP_BODY_BYTES + 1) as u64);\n        let mut decoded = Vec::new();\n        limited.read_to_end(&mut decoded)?;\n        if decoded.len() > MAX_HTTP_BODY_BYTES {\n            anyhow::bail!(\"解压后的请求体超过大小限制\");\n        }\n        decoded\n    } else {\n        anyhow::bail!(\"不支持的 Content-Encoding：{encoding}\");\n    };\n\n    String::from_utf8(decoded)\n        .map_err(|error| anyhow::anyhow!(\"Responses 请求体不是 UTF-8：{error}\"))\n}\n\nfn overlay_image_response() -> (String, Vec<u8>, String, &'static str) {\n    let not_found = || {\n        (\n            \"404 Not Found\".to_string(),\n            serde_json::to_vec(&serde_json::json!({\n                \"status\": \"failed\",\n                \"message\": \"图片覆盖层未启用或图片不可用\"\n            }))\n            .unwrap_or_default(),\n            \"application/json; charset=utf-8\".to_string(),\n            \"helper.overlay_image_not_found\",\n        )\n    };\n    let settings = SettingsStore::default().load().unwrap_or_default();\n    if !settings.codex_app_image_overlay_enabled {\n        return not_found();","sourceCodeStart":1435,"sourceCodeEnd":1471,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/launcher.rs#L1435-L1471","documentation":"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.","triggerScenarios":"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.","commonSituations":"Proxying a client that sends binary payloads; a server/client mismatch on charset; corrupted middlebox responses; incorrectly labeled encoding causing wrong decompression.","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"],"exampleFix":"// before\nbody bytes: b\"\\xff\\xfe{...}\" // invalid UTF-8\n// after\nString::from_utf8_lossy(&decoded).into_owned() // or send valid UTF-8 JSON","handlingStrategy":"try-catch","validationCode":"// check the header before decoding\nmatch req.header(\"content-encoding\") {\n    Some(e) if matches!(e.to_ascii_lowercase().as_str(), \"gzip\"|\"deflate\"|\"br\"|\"identity\") => {},\n    other => return reject_unsupported_encoding(other),\n}","typeGuard":null,"tryCatchPattern":"match decode_responses_body(raw, encoding) {\n    Err(e) if e.to_string().contains(\"不是 UTF-8\") => {\n        // log a truncated hex dump and return 400 to the client\n        respond_bad_request(\"request body must be UTF-8 text\");\n    }\n    other => other?,\n}","preventionTips":["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"],"tags":["http","encoding","proxy"],"backgroundTag":"json-decode-failed","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}