{"record":{"id":"f3ebe1697c907bff","repo":"influxdata/influxdb","slug":"the-mime-type-specified-was-not-valid-utf8-0-http","errorCode":null,"errorMessage":"the mime type specified was not valid UTF8: {0}","messagePattern":"the mime type specified was not valid UTF8: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":400,"severity":"error","filePath":"influxdb3_types/src/http.rs","lineNumber":63,"sourceCode":"    where\n        D: serde::Deserializer<'a>,\n    {\n        let s = String::deserialize(deserializer)?;\n        match s.as_str() {\n            \"never\" => Ok(Self::Never),\n            \"now\" => Ok(Self::Now),\n            \"default\" => Ok(Self::Default),\n            timestamp => Ok(Self::Timestamp(timestamp.to_string())),\n        }\n    }\n}\n\n#[derive(Debug, thiserror::Error)]\npub enum Error {\n    #[error(\"invalid mime type ({0})\")]\n    InvalidMimeType(String),\n\n    #[error(\"the mime type specified was not valid UTF8: {0}\")]\n    NonUtf8MimeType(#[from] std::string::FromUtf8Error),\n\n    #[error(transparent)]\n    Unexpected(#[from] anyhow::Error),\n}\n\nimpl From<&Error> for hyper::StatusCode {\n    fn from(value: &Error) -> Self {\n        match value {\n            Error::InvalidMimeType(_) | Error::NonUtf8MimeType(_) => Self::BAD_REQUEST,\n            Error::Unexpected(_) => Self::INTERNAL_SERVER_ERROR,\n        }\n    }\n}\n\n#[derive(Clone, Debug, Deserialize, Serialize)]\npub struct PingResponse {\n    #[serde(default)]","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/influxdb3_types/src/http.rs#L45-L81","documentation":"Error::NonUtf8MimeType in influxdb3_types::http is thrown when the raw mime type bytes are not valid UTF-8. It wraps std::string::FromUtf8Error via #[from], so any FromUtf8Error encountered while converting a mime type into a String is converted automatically. Valid media types must be UTF-8 encodable to be handled.","triggerScenarios":"Converting header/body bytes to a String when the Content-Type value contains non-UTF-8 bytes (e.g. latin-1 encoded bytes, binary garbage) and the FromUtf8Error is converted into this Error.","commonSituations":"Clients with broken encoders sending non-ASCII bytes in headers, gateways mangling Content-Type, legacy systems using ISO-8859-1 header values.","solutions":["Ensure the client/gateway sends ASCII/UTF-8 Content-Type headers","Re-encode or sanitize the incoming header bytes to lossy UTF-8 before parsing","Reject or log-and-drop requests with non-UTF-8 headers at the edge"],"exampleFix":"// before\nlet mime = String::from_utf8(bytes)?; // panics into error on bad bytes\n// after\nlet mime = String::from_utf8_lossy(&bytes).to_string(); // or reject request with 400","handlingStrategy":"validation","validationCode":"fn header_is_utf8(bytes: &[u8]) -> bool {\n    std::str::from_utf8(bytes).is_ok()\n}","typeGuard":"fn lossy_mime(bytes: &[u8]) -> Option<String> {\n    std::str::from_utf8(bytes).ok().map(|s| s.to_string())\n}","tryCatchPattern":"match result {\n    Ok(v) => v,\n    Err(Error::NonUtf8MimeType(src)) => /* 400 Bad Request: non-UTF-8 Content-Type */,\n    Err(e) => return Err(e),\n}","preventionTips":["Enforce ASCII-only header values at the proxy/edge","Use from_utf8_lossy only for logging, not for accepted values","Reject malformed requests early with 400"],"tags":["http","mime","utf8","encoding"],"backgroundTag":"invalid-argument-format","analyzedSha":"06200ef96ba82c5f6727e5038a83af8e722c6875","analyzedAt":"2026-09-19T12:55:30.003Z","contentChangedAt":"2026-09-19T12:55:30.003Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}