{"record":{"id":"fe2e9d7c189ba4cb","repo":"quarkusio/quarkus","slug":"the-content-type-header-value-did-not-correspond-t","errorCode":null,"errorMessage":"The content-type header value did not correspond to a valid media type","messagePattern":"The content-type header value did not correspond to a valid media type","errorType":"http","errorClass":"NotSupportedException","httpStatus":415,"severity":"error","filePath":"independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/HandlerMediaTypeUtil.java","lineNumber":39,"sourceCode":"\n    private static final String INVALID_ACCEPT_HEADER_MESSAGE = \"The accept header value did not match the value in @Produces\";\n    private static final String MALFORMED_ACCEPT_HEADER_MESSAGE = \"The accept header value did not correspond to a valid media type\";\n\n    // according to the spec we need to return HTTP 415 when content-type header doesn't match what is specified in @Consumes\n    // HttpMethod being null means this is a sub resource locator method. The handler chain of the sub resource has to match the content-type header\n    static void validateConsumes(RequestMapper.RequestMatch<RuntimeResource> target,\n            ResteasyReactiveRequestContext requestContext) {\n        if (target.value.getHttpMethod() != null && !target.value.getConsumes().isEmpty()) {\n            String contentType = (String) requestContext.getHeader(HttpHeaders.CONTENT_TYPE, true);\n            if (contentType != null) {\n                try {\n                    if (MediaTypeHelper.getFirstMatch(\n                            target.value.getConsumes(),\n                            Collections.singletonList(MediaTypeHelper.valueOf(contentType))) == null) {\n                        throw new NotSupportedException(\"The content-type header value did not match the value in @Consumes\");\n                    }\n                } catch (IllegalArgumentException e) {\n                    throw new NotSupportedException(\"The content-type header value did not correspond to a valid media type\");\n                }\n            }\n        }\n    }\n\n    // according to the spec we need to return HTTP 406 when Accept header doesn't match what is specified in @Produces.\n    // A fully unparseable Accept header is a client syntax error and returns HTTP 400 instead.\n    // HttpMethod being null means this is a sub resource locator method. The handler chain of the sub resource has to match the accept header\n    static void validateProduces(RequestMapper.RequestMatch<RuntimeResource> target,\n            ResteasyReactiveRequestContext requestContext) {\n        if (target.value.getHttpMethod() != null && target.value.getProduces() != null) {\n            // there could potentially be multiple Accept headers and we need to response with 406\n            // if none match the method's @Produces\n            List<String> accepts = (List<String>) requestContext.getHeader(HttpHeaders.ACCEPT, false);\n            if (!accepts.isEmpty()) {\n                boolean hasAtLeastOneMatch = false;\n                boolean sawParseableAccept = false;\n                for (int i = 0; i < accepts.size(); i++) {","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/HandlerMediaTypeUtil.java#L21-L57","documentation":"RESTEasy Reactive throws this NotSupportedException (HTTP 415) when the request's Content-Type header cannot be parsed as a valid media type. In validateConsumes, MediaTypeHelper.valueOf(contentType) throws IllegalArgumentException for syntactically invalid values, which is caught and rethrown as this NotSupportedException. This is a client-side syntax error in the header, distinct from a valid type that merely does not match @Consumes.","triggerScenarios":"A request to a @Consumes-annotated endpoint carries a Content-Type header that MediaTypeHelper.valueOf cannot parse — e.g. 'Content-Type: application/json; charset=' (empty parameter), 'Content-Type: json' (no type/subtype), or other malformed header values that fail MediaTypeHeaderDelegate parsing.","commonSituations":"Hand-rolled HTTP clients or curl invocations with typo'd headers; proxies or middleware rewriting/duplicating the Content-Type header; template placeholders left unrendered (e.g. 'Content-Type: ${contentType}'); charset parameter with missing value.","solutions":["Inspect the outgoing request and correct the Content-Type header to a well-formed type/subtype value such as application/json or text/plain.","Validate header construction in the client code — ensure no empty parameters, missing slashes, or unrendered template variables.","If a proxy/gateway rewrites headers, fix its header manipulation configuration."],"exampleFix":"// before (client)\nrequest.setHeader(\"Content-Type\", \"json\");\n// after\nrequest.setHeader(\"Content-Type\", \"application/json\");","handlingStrategy":"validation","validationCode":"// validate before sending\ntry {\n    jakarta.ws.rs.core.MediaType.valueOf(contentType);\n} catch (IllegalArgumentException e) {\n    throw new IllegalStateException(\"Malformed Content-Type header: \" + contentType, e);\n}","typeGuard":null,"tryCatchPattern":"try {\n    return client.post(entity);\n} catch (BadRequestException | NotSupportedException e) {\n    log.error(\"Check Content-Type header format\", e);\n    throw e;\n}","preventionTips":["Use MediaType constants instead of raw strings when building headers.","Never build header values from unvalidated user input or unrendered templates.","Add a client-side unit test asserting well-formed headers."],"tags":["rest","http-415","content-type","malformed-header"],"backgroundTag":"malformed-content-type-header","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}