{"record":{"id":"ce488564f064929a","repo":"micro/go-micro","slug":"unsupported-content-type","errorCode":null,"errorMessage":"unsupported Content-Type","messagePattern":"unsupported Content-Type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"codec/grpc/grpc.go","lineNumber":67,"sourceCode":"func (c *Codec) ReadBody(b interface{}) error {\n\t// no body\n\tif b == nil {\n\t\treturn nil\n\t}\n\n\t_, buf, err := decode(c.Conn)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tswitch c.ContentType {\n\tcase \"application/grpc+json\":\n\t\treturn json.Unmarshal(buf, b)\n\tcase \"application/grpc+proto\", \"application/grpc\":\n\t\treturn proto.Unmarshal(buf, b.(proto.Message))\n\t}\n\n\treturn errors.New(\"unsupported Content-Type\")\n}\n\nfunc (c *Codec) Write(m *codec.Message, b interface{}) error {\n\tvar buf []byte\n\tvar err error\n\n\tif ct := m.Header[\"Content-Type\"]; len(ct) > 0 {\n\t\tc.ContentType = ct\n\t}\n\n\tif ct := m.Header[\"content-type\"]; len(ct) > 0 {\n\t\tc.ContentType = ct\n\t}\n\n\tswitch m.Type {\n\tcase codec.Request:\n\t\tparts := strings.Split(m.Endpoint, \".\")\n\t\tm.Header[\":method\"] = \"POST\"","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/codec/grpc/grpc.go#L49-L85","documentation":"The go-micro gRPC codec can only decode message bodies for a fixed set of content types: application/grpc+json, application/grpc+proto, and application/grpc. ReadBody decodes the length-prefixed frame from the connection and then switches on the codec's stored ContentType; any other content type falls through to this error, leaving the body undecoded.","triggerScenarios":"ReadBody is called after ReadHeader stored a ContentType that is not one of the three supported values — e.g. a request with \"content-type: application/grpc+protobuf\" (misspelled), \"text/plain\", \"application/json\" (without the grpc prefix), or an empty content-type header on the incoming stream.","commonSituations":"A client library or proxy sends a content-type that differs slightly from what go-micro expects (e.g. application/grpc-web, or a charset suffix like \"application/grpc+proto; charset=utf-8\"); a custom codec was registered on one side but not the other; tests forget to set the content-type header.","solutions":["Set the request/response content-type to exactly \"application/grpc+proto\", \"application/grpc\", or \"application/grpc+json\" on both client and server.","Strip any media-type parameters (charset etc.) or normalize the content-type before it reaches the codec.","If you need another format, register/use a codec that supports it instead of the gRPC codec.","Align codec configuration between client and server so both negotiate the same content type."],"exampleFix":"// before\nreq.Header.Set(\"Content-Type\", \"application/grpc+protobuf\")\n// after\nreq.Header.Set(\"Content-Type\", \"application/grpc+proto\")","handlingStrategy":"validation","validationCode":"ct := header.Get(\"Content-Type\")\nbase := strings.TrimSpace(strings.Split(ct, \";\")[0])\nswitch base {\ncase \"application/grpc+json\", \"application/grpc+proto\", \"application/grpc\":\n    // ok\ndefault:\n    return fmt.Errorf(\"content-type %q not supported by grpc codec\", ct)\n}","typeGuard":"func supportedCT(ct string) bool {\n    switch strings.TrimSpace(strings.Split(ct, \";\")[0]) {\n    case \"application/grpc+json\", \"application/grpc+proto\", \"application/grpc\":\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Hardcode one of the three supported content types in client setup.","Normalize content-type (strip charset params, lowercase) in middleware.","Keep codec configuration symmetric between client and server.","Integration-test with a real gRPC client to catch header drift."],"tags":["grpc","codec","content-type","go"],"backgroundTag":"unsupported-content-type","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}