influxdata/influxdb · error · Error::NonUtf8ContentTypeHeader
invalid content-type header
Error message
invalid content-type header: {0} What it means
`Error::NonUtf8ContentTypeHeader` is returned when the `Content-Type` header value cannot be read as a string (wrapping `hyper::header::ToStrError`). Like all HTTP headers, it must be visible ASCII for the server to parse the MIME type.
Solutions
- Send a standard ASCII media type such as "application/json", "text/plain", or "application/vnd.influxdb.v3+csv"
- Validate/sanitize any dynamic Content-Type value before inserting it into the request
- Check the client or proxy producing the request for header corruption
- Omit the header if the server can infer the type for the endpoint
Example fix
// before
headers.insert("Content-Type", HeaderValue::from_bytes(format!("text/{}", user_mime).as_bytes()).unwrap());
// after
headers.insert("Content-Type", HeaderValue::from_static("text/plain")); Defensive patterns
Strategy: validation
Validate before calling
const ALLOWED = new Set(['application/json','text/plain','application/vnd.influxdb.v3+csv']);
if (!ALLOWED.has(contentType)) throw new Error('bad content-type: ' + contentType); Prevention
- Use standard media-type constants, not ad-hoc strings
- Sanitize any dynamic Content-Type values
- Check proxies don't rewrite headers
- Document required content types per endpoint
When it happens
Trigger: Sending a request whose `Content-Type` header contains non-ASCII bytes — e.g. UTF-8 characters in the media type, control characters, or a client building the header from unvalidated input.
Common situations: Custom HTTP clients inserting user-supplied or localized strings into Content-Type, misbehaving proxies, or template-generated requests where the content type string was interpolated incorrectly.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- invalid content-encoding header
- invalid mime type ( )
- unacceptable content-type, expected
- arrow error
- Authorization header was malformed, the request was not in…
AI-assisted analysis of influxdata/influxdb@06200ef96b (2026-09-19).
Data as JSON: /api/errors/529197e17da5de09.
Report an issue: GitHub.
Appendix: source
Thrown at influxdb3_server/src/http.rs:208
}
}
#[derive(Debug, Error)]
pub enum Error {
/// The requested path has no registered handler.
#[error("not found")]
NoHandler,
/// The request body content is not valid utf8.
#[error("body content is not valid utf8: {0}")]
NonUtf8Body(Utf8Error),
/// The `Content-Encoding` header is invalid and cannot be read.
#[error("invalid content-encoding header: {0}")]
NonUtf8ContentEncodingHeader(hyper::header::ToStrError),
/// The `Content-Type` header is invalid and cannot be read.
#[error("invalid content-type header: {0}")]
NonUtf8ContentTypeHeader(hyper::header::ToStrError),
/// The specified `Content-Encoding` is not acceptable.
#[error("unacceptable content-encoding: {0}")]
InvalidContentEncoding(String),
/// The specified `Content-Type` is not acceptable.
#[error("unacceptable content-type, expected: {expected}")]
InvalidContentType { expected: mime::Mime },
/// The client disconnected.
#[error("client disconnected")]
ClientHangup(Box<dyn std::error::Error + Send + Sync>),
/// The client sent a request body that exceeds the configured maximum.
#[error("max request size ({0} bytes) exceeded")]
RequestSizeExceeded(usize),
View on GitHub (pinned to 06200ef96b)