I solved it with the help of this answer:
private class ForcableContentTypeWrapper extends HttpServletResponseWrapper
{
public ForcableContentTypeWrapper(HttpServletResponse response)
{
super(response);
}
@Override
public void setContentType(String type)
{
}
public void forceContentType(String type)
{
super.setContentType(type);
}
}
Then changed my above code to:
if (reqUrl.endsWith(gzExt))
{
ForcableContentTypeWrapper newResponse = new ForcableContentTypeWrapper(response);
newResponse.setHeader("Content-Encoding", "gzip");
newResponse.forceContentType("text/javascript");
filterChain.doFilter(request, newResponse);
return;
}
Its not a pretty workaround, but it works.