micro/go-micro · error
unsupported Content-Type: %s
Error message
unsupported Content-Type: %s
What it means
The generic rpcClient's newCodec looked up the request Content-Type in DefaultCodecs and found no match, so it cannot encode the request. This happens for the default (mucp/rpc) client, independent of the gRPC-specific check, and fails the call/stream/Publish before any network I/O.
Source
Thrown at client/rpc_client.go:76
// wrap in reverse
for i := len(opts.Wrappers); i > 0; i-- {
c = opts.Wrappers[i-1](c)
}
return c
}
func (r *rpcClient) newCodec(contentType string) (codec.NewCodec, error) {
if c, ok := r.opts.Codecs[contentType]; ok {
return c, nil
}
if cf, ok := DefaultCodecs[contentType]; ok {
return cf, nil
}
return nil, fmt.Errorf("unsupported Content-Type: %s", contentType)
}
func (r *rpcClient) call(
ctx context.Context,
node *registry.Node,
req Request,
resp interface{},
opts CallOptions,
) error {
// In-process fast-path: if the callee runs in this process and both bodies
// are raw frames, dispatch directly and skip the network entirely.
if handled, err := r.localCall(ctx, req, resp); handled {
return err
}
address := node.Address
logger := r.Options().Logger
View on GitHub (pinned to 24529f1404)
Solutions
- Use a supported Content-Type such as application/json, application/protobuf, or application/octet-stream (see DefaultCodecs)
- Fix the typo in the ContentType client option
- Register a custom codec in DefaultCodecs at startup if the format is genuinely needed
- Log/inspect the configured ContentType at boot to catch drift
Example fix
// before
client.ContentType("application/xml")
// after
client.ContentType("application/json") Defensive patterns
Strategy: validation
Validate before calling
var supported = []string{"application/json", "application/protobuf", "application/octet-stream"}
if !slices.Contains(supported, clientOptsContentType) {
return fmt.Errorf("content type %q not in DefaultCodecs", clientOptsContentType)
} Try / catch
err := client.Publish(ctx, topic, msg)
if err != nil && strings.Contains(err.Error(), "unsupported Content-Type") {
// correct client.ContentType to a DefaultCodecs entry
} Prevention
- Define content types as named constants
- Check DefaultCodecs when choosing a ContentType value
- Cover client setup in startup smoke tests
- Avoid ad-hoc overrides in middleware
When it happens
Trigger: Configuring client.ContentType (or a service's advertised content type) to a value absent from DefaultCodecs — e.g. "application/xml", "text/plain", or a misspelled "applcation/json" — then calling call, Stream, or Publish.
Common situations: Typos in content-type strings; copying options between transports where the codec sets differ; middleware or plugins overriding ContentType with an unsupported value.
Related errors
- unsupported Content-Type: %s
- unsupported Content-Type
- rpc.Handle: handler has no name
- Unable to encode body
- agent: ResumeStreamAsk requires a checkpoint
AI-assisted analysis of micro/go-micro@24529f1404 (2026-09-01).
Data as JSON: /api/errors/65c2d6ba1193a56e.
Report an issue: GitHub.