Skip to content

getAcceptableMediaTypes call in PreMatching filter prevent resource matching with manipulated accept headers #5317

@nmuser

Description

@nmuser

I'm using accept headers for rest api versioning. A @PreMatching request filter is used to set a default rest api version in case the client does not specify the version:

@Provider
@PreMatching
public class APIVersionRequestFilterr implements ContainerRequestFilter  {
  @Override
  public void filter(ContainerRequestContext containerRequestContext) throws IOException {
    List<MediaType> mediaTypes = containerRequestContext.getAcceptableMediaTypes();
    containerRequestContext.getHeaders().get("accept").add("application/vnd.x.qi-v3.0+json");
  }
}

When I use getAcceptableMediaTypes() to check if the client requested a specific version the following accept header modification has no effect for the resource matching.

When i do not call getAcceptableMediaTypes or use jersey < 2.38 the accept header modification effects the resource matching:

@Path("/")
public class VersionV3{

  @Post
  @Produces({"application/vnd.x.qi-v3.0+json" })
  @Path("/service")
  public Response do(){
    return Response.ok().build();
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions