{"record":{"id":"68cf12d3b7fe06ec","repo":"quarkusio/quarkus","slug":"the-accept-header-value-did-not-correspond-to-a-va","errorCode":null,"errorMessage":"The accept header value did not correspond to a valid media type","messagePattern":"The accept header value did not correspond to a valid media type","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/HandlerMediaTypeUtil.java","lineNumber":71,"sourceCode":"            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++) {\n                    try {\n                        boolean matches = acceptHeaderMatches(target, accepts.get(i));\n                        sawParseableAccept = true;\n                        if (matches) {\n                            hasAtLeastOneMatch = true;\n                            break;\n                        }\n                    } catch (IllegalArgumentException ignored) {\n                        // the provided header contained no parseable media type tokens\n                    }\n                }\n                if (!hasAtLeastOneMatch) {\n                    if (!sawParseableAccept) {\n                        throw new BadRequestException(MALFORMED_ACCEPT_HEADER_MESSAGE);\n                    }\n                    throw new NotAcceptableException(INVALID_ACCEPT_HEADER_MESSAGE);\n                }\n            }\n\n            requestContext.setProducesChecked(true);\n        }\n    }\n\n    /**\n     * @return {@code true} if the provided string matches one of the {@code @Produces} values of the resource method\n     * @throws IllegalArgumentException if the provided string contains no parseable media type tokens\n     */\n    private static boolean acceptHeaderMatches(RequestMapper.RequestMatch<RuntimeResource> target, String accepts) {\n        if ((accepts != null) && !accepts.equals(MediaType.WILDCARD)) {\n            int commaIndex = accepts.indexOf(',');\n            boolean multipleAcceptsValues = commaIndex >= 0;\n            MediaType[] producesMediaTypes = target.value.getProduces().getSortedOriginalMediaTypes();","sourceCodeStart":53,"sourceCodeEnd":89,"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#L53-L89","documentation":"RESTEasy Reactive throws this BadRequestException (HTTP 400) when the client's Accept header(s) contain no parseable media type tokens at all. In validateProduces, each Accept header is tried via acceptHeaderMatches which throws IllegalArgumentException for unparseable values; if every header failed to parse (sawParseableAccept is false), the request is rejected as a client syntax error with HTTP 400. This is deliberately distinguished from HTTP 406 (valid Accept that simply doesn't match @Produces).","triggerScenarios":"All Accept headers sent by the client fail to parse in acceptHeaderMatches — e.g. 'Accept: */' (truncated wildcard), 'Accept: application' (no subtype), 'Accept: ,,,' (only commas) — so acceptHeaderMatches throws IllegalArgumentException for every header and sawParseableAccept remains false.","commonSituations":"Buggy HTTP clients or hand-built requests with malformed Accept headers; security scanners/proxies corrupting headers; HTML forms or template code emitting truncated Accept values.","solutions":["Fix the client to send a valid Accept header, e.g. 'Accept: application/json' or omit it entirely (defaults to */*).","Check intermediary proxies/gateways for header corruption or truncation.","Test the endpoint with curl -H 'Accept: application/json' to confirm the server side is fine."],"exampleFix":"// before (client)\nhttpClient.header(\"Accept\", \"application\");\n// after\nhttpClient.header(\"Accept\", \"application/json\");","handlingStrategy":"validation","validationCode":"// validate Accept header client-side\nfor (String token : acceptHeader.split(\",\")) {\n    try {\n        jakarta.ws.rs.core.MediaType.valueOf(token.trim());\n    } catch (IllegalArgumentException e) {\n        throw new IllegalStateException(\"Malformed Accept token: \" + token);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    return target.request(acceptHeader).get();\n} catch (BadRequestException e) {\n    log.error(\"Accept header was unparseable: {}\", acceptHeader, e);\n    throw e;\n}","preventionTips":["Omit the Accept header rather than sending a guessed value.","Use standard media-type constants from client code.","Test HTTP clients against a local endpoint with header logging."],"tags":["rest","http-400","accept-header","malformed-header"],"backgroundTag":"malformed-accept-header","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}