quarkusio/quarkus · error · BadRequestException

The accept header value did not correspond to a valid media

Error message

The accept header value did not correspond to a valid media type

What it means

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).

Source

Thrown at independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/HandlerMediaTypeUtil.java:71

            List<String> accepts = (List<String>) requestContext.getHeader(HttpHeaders.ACCEPT, false);
            if (!accepts.isEmpty()) {
                boolean hasAtLeastOneMatch = false;
                boolean sawParseableAccept = false;
                for (int i = 0; i < accepts.size(); i++) {
                    try {
                        boolean matches = acceptHeaderMatches(target, accepts.get(i));
                        sawParseableAccept = true;
                        if (matches) {
                            hasAtLeastOneMatch = true;
                            break;
                        }
                    } catch (IllegalArgumentException ignored) {
                        // the provided header contained no parseable media type tokens
                    }
                }
                if (!hasAtLeastOneMatch) {
                    if (!sawParseableAccept) {
                        throw new BadRequestException(MALFORMED_ACCEPT_HEADER_MESSAGE);
                    }
                    throw new NotAcceptableException(INVALID_ACCEPT_HEADER_MESSAGE);
                }
            }

            requestContext.setProducesChecked(true);
        }
    }

    /**
     * @return {@code true} if the provided string matches one of the {@code @Produces} values of the resource method
     * @throws IllegalArgumentException if the provided string contains no parseable media type tokens
     */
    private static boolean acceptHeaderMatches(RequestMapper.RequestMatch<RuntimeResource> target, String accepts) {
        if ((accepts != null) && !accepts.equals(MediaType.WILDCARD)) {
            int commaIndex = accepts.indexOf(',');
            boolean multipleAcceptsValues = commaIndex >= 0;
            MediaType[] producesMediaTypes = target.value.getProduces().getSortedOriginalMediaTypes();

View on GitHub (pinned to e1c734241f)

Solutions

  1. Fix the client to send a valid Accept header, e.g. 'Accept: application/json' or omit it entirely (defaults to */*).
  2. Check intermediary proxies/gateways for header corruption or truncation.
  3. Test the endpoint with curl -H 'Accept: application/json' to confirm the server side is fine.

Example fix

// before (client)
httpClient.header("Accept", "application");
// after
httpClient.header("Accept", "application/json");
Defensive patterns

Strategy: validation

Validate before calling

// validate Accept header client-side
for (String token : acceptHeader.split(",")) {
    try {
        jakarta.ws.rs.core.MediaType.valueOf(token.trim());
    } catch (IllegalArgumentException e) {
        throw new IllegalStateException("Malformed Accept token: " + token);
    }
}

Try / catch

try {
    return target.request(acceptHeader).get();
} catch (BadRequestException e) {
    log.error("Accept header was unparseable: {}", acceptHeader, e);
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/68cf12d3b7fe06ec. Report an issue: GitHub.