jersey-1.x icon indicating copy to clipboard operation
jersey-1.x copied to clipboard

Don't add "Vary: Accept-Encoding" header to the response if it's already exists

Open vadyalex opened this issue 9 years ago • 2 comments

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.

vadyalex avatar Jun 10 '15 14:06 vadyalex

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.

vadyalex avatar Jun 21 '15 13:06 vadyalex

Note that Jersey 2.0 shares my train of thought - do not add if it's already there. Refer to correspondent code.

vadyalex avatar Jun 21 '15 13:06 vadyalex