jersey-1.x
jersey-1.x copied to clipboard
Don't add "Vary: Accept-Encoding" header to the response if it's already exists
GZIPContentEncodingFilter
modifies response header by adding "Vary: Accept-Encoding" even if it's already exists.
This side effect behaviour may lead to nasty problems..
For example, there is an JAX-RS resource:
@Path("/myResource")
public class SomeResource {
public static final Response OK = Response.ok().build();
@GET
public Response doGet() {
return OK;
}
}
Because Response
class is mutable every time GZIPContentEncodingFilter
processes request-response containers it will add "Vary: Accept-Encoding".
Since SomeResource.OK
lives during application lifetime header size will grow until overgrows maximum header limit size allowed by underlying Servlet Container and application will not be able to process current resource.
Even though I would say improper design of Response
rather than improper use adding "Vary: Accept-Encoding" to the response object even if it's already there is a bug.
Note that Jersey 2.0 shares my train of thought - do not add if it's already there. Refer to correspondent code.