{"record":{"id":"c30a452d7a731354","repo":"quarkusio/quarkus","slug":"the-accept-header-value-did-not-match-the-value-in","errorCode":null,"errorMessage":"The accept header value did not match the value in @Produces","messagePattern":"The accept header value did not match the value in @Produces","errorType":"http","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/HandlerMediaTypeUtil.java","lineNumber":73,"sourceCode":"                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();\n            if (!multipleAcceptsValues && (producesMediaTypes.length == 1)) {\n                // the point of this branch is to eliminate any list creation or string indexing as none is needed","sourceCodeStart":55,"sourceCodeEnd":91,"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#L55-L91","documentation":"RESTEasy Reactive throws this NotAcceptableException (HTTP 406) when the client's Accept header is valid but none of its media types are compatible with the @Produces media types of the target resource method. validateProduces iterates all Accept headers, and if at least one parsed successfully (sawParseableAccept true) but hasAtLeastOneMatch stayed false, it throws this exception per the JAX-RS spec's content negotiation rules.","triggerScenarios":"A request to a method with @Produces whose Accept header parses but matches nothing — e.g. 'Accept: application/xml' against @Produces(MediaType.APPLICATION_JSON), or 'Accept: text/csv' against an endpoint that only produces JSON.","commonSituations":"Browser sending 'Accept: text/html' to a JSON API endpoint; clients requesting a format (XML, CSV) the endpoint never implemented; API version changes that dropped a media type; misconfigured REST client content negotiators.","solutions":["Change the client's Accept header to include a media type the endpoint produces, e.g. 'Accept: application/json'.","Add the requested media type to the server's @Produces and add a corresponding message body writer.","Use 'Accept: */*' to accept any response media type the endpoint offers."],"exampleFix":"// before (client)\nGET /api/users  Accept: application/xml\n// after\nGET /api/users  Accept: application/json","handlingStrategy":"validation","validationCode":"// ensure requested type is in the endpoint's @Produces set before calling\njava.util.Set<String> produces = java.util.Set.of(\"application/json\");\nif (!produces.contains(requestedAccept)) {\n    requestedAccept = \"application/json\"; // fall back to a produced type\n}","typeGuard":null,"tryCatchPattern":"try {\n    return client.get();\n} catch (NotAcceptableException e) {\n    // HTTP 406: retry with Accept: */* or the documented produced type\n    return client.accept(\"*/*\").get();\n}","preventionTips":["Read the endpoint's OpenAPI/Swagger docs for supported response media types.","Send 'Accept: */*' when the format doesn't matter.","Keep client Accept configuration aligned with server @Produces updates."],"tags":["rest","http-406","accept-header","content-negotiation"],"backgroundTag":"not-acceptable-media-type","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"}