public class CompressionFilter extends Object implements javax.servlet.Filter
HttpServletResponse
so that it understands "Content-Encoding: gzip" and compress the response.
When exceptions are processed within web applications, different unrelated parts of the webapp can end up calling
ServletResponse.getOutputStream()
. This fundamentally doesn't work with the notion that the application
needs to process "Content-Encoding:gzip" on its own. Such app has to maintain a GZIP output stream on its own,
since HttpServletResponse
doesn't know that its output is written through a compressed stream.
Another place this break-down can be seen is when a servlet throws an exception that the container handles. It tries to render an error page, but of course it wouldn't know that "Content-Encoding:gzip" is set, so it will fail to write in the correct format.
The only way to properly fix this is to make HttpServletResponse
smart enough that it returns
the compression-transparent stream from ServletResponse.getOutputStream()
(and it would also
have to process the exception thrown from the app.) This filter does exactly that.
Modifier and Type | Field and Description |
---|---|
static boolean |
DISABLED
Disables the effect of
setUncaughtExceptionHandler(javax.servlet.ServletContext, org.kohsuke.stapler.compression.UncaughtExceptionHandler) , letting all errors be rethrown. |
Constructor and Description |
---|
CompressionFilter() |
Modifier and Type | Method and Description |
---|---|
static boolean |
activate(javax.servlet.ServletRequest req)
Is this request already wrapped into
CompressionFilter ,
activate that, so that ServletResponse.getOutputStream() will return
a stream that automatically handles compression. |
void |
destroy() |
void |
doFilter(javax.servlet.ServletRequest _req,
javax.servlet.ServletResponse _rsp,
javax.servlet.FilterChain filterChain) |
static UncaughtExceptionHandler |
getUncaughtExceptionHandler(javax.servlet.ServletContext context) |
static boolean |
has(javax.servlet.ServletRequest req)
Is this request already wrapped into
CompressionFilter ? |
void |
init(javax.servlet.FilterConfig filterConfig) |
static void |
setUncaughtExceptionHandler(javax.servlet.ServletContext context,
UncaughtExceptionHandler handler) |
public static boolean DISABLED
setUncaughtExceptionHandler(javax.servlet.ServletContext, org.kohsuke.stapler.compression.UncaughtExceptionHandler)
, letting all errors be rethrown.
Despite its name, this flag does not disable CompressionFilter
itself!
Rather use DefaultScriptInvoker.COMPRESS_BY_DEFAULT
.public void init(javax.servlet.FilterConfig filterConfig) throws javax.servlet.ServletException
init
in interface javax.servlet.Filter
javax.servlet.ServletException
public void doFilter(javax.servlet.ServletRequest _req, javax.servlet.ServletResponse _rsp, javax.servlet.FilterChain filterChain) throws IOException, javax.servlet.ServletException
doFilter
in interface javax.servlet.Filter
IOException
javax.servlet.ServletException
public void destroy()
destroy
in interface javax.servlet.Filter
public static void setUncaughtExceptionHandler(javax.servlet.ServletContext context, UncaughtExceptionHandler handler)
public static UncaughtExceptionHandler getUncaughtExceptionHandler(javax.servlet.ServletContext context)
public static boolean has(javax.servlet.ServletRequest req)
CompressionFilter
?public static boolean activate(javax.servlet.ServletRequest req) throws IOException
CompressionFilter
,
activate that, so that ServletResponse.getOutputStream()
will return
a stream that automatically handles compression.IOException
Copyright © 2017. All rights reserved.