caddyserver/caddy · warning
malformed Content-Type
Error message
malformed Content-Type
What it means
Returned when the parsed media type contains no '/' after strings.Cut, meaning the adapter name cannot be extracted. In practice this is nearly unreachable because mime.ParseMediaType already rejects slash-less types, so it exists as a defensive check. If seen, it indicates a type that passed MIME parsing but has no subtype component.
Source
Thrown at caddyconfig/load.go:201
}
ct, _, err := mime.ParseMediaType(contentType)
if err != nil {
return nil, nil, caddy.APIError{
HTTPStatus: http.StatusBadRequest,
Err: fmt.Errorf("invalid Content-Type: %v", err),
}
}
// if already JSON, no need to adapt
if strings.HasSuffix(ct, "/json") {
return body, nil, nil
}
// adapter name should be suffix of MIME type
_, adapterName, slashFound := strings.Cut(ct, "/")
if !slashFound {
return nil, nil, fmt.Errorf("malformed Content-Type")
}
cfgAdapter := GetAdapter(adapterName)
if cfgAdapter == nil {
return nil, nil, fmt.Errorf("unrecognized config adapter '%s'", adapterName)
}
result, warnings, err := cfgAdapter.Adapt(body, nil)
if err != nil {
return nil, nil, fmt.Errorf("adapting config using %s adapter: %v", adapterName, err)
}
return result, warnings, nil
}
var bufPool = sync.Pool{
New: func() any {
return new(bytes.Buffer)View on GitHub (pinned to 50e54ee279)
Solutions
- Set a standard type/subtype Content-Type such as text/caddyfile or application/json
- Omit Content-Type to send raw JSON and bypass adaptation entirely
Defensive patterns
Strategy: validation
Validate before calling
// require a slash in the media type before calling the API
mt, _, err := mime.ParseMediaType(ct)
if err != nil || !strings.Contains(mt, "/") {
return fmt.Errorf("Content-Type must be type/subtype, got %q", ct)
} Prevention
- Use standard MIME types; this branch is near-unreachable with well-formed headers
When it happens
Trigger: A Content-Type value that mime.ParseMediaType accepts yet contains no slash — essentially only possible via exotic or future MIME parser quirks; practically never observed in the wild.
Common situations: Almost none; occasionally reproduced by fuzzing or by clients that send non-standard header values that slip through lenient intermediaries.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- invalid Content-Type: %v
- unrecognized config adapter '%s'
- no metrics registry found
- provisioning admin router module %s: %v
- loading identity issuer modules: %s
AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15).
Data as JSON: /api/errors/eb8fd16b9942f45b.
Report an issue: GitHub.