| 1 |
|
package com.atlassian.core.filters.gzip; |
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
import com.atlassian.core.filters.AbstractFilter; |
| 14 |
|
import org.apache.log4j.Category; |
| 15 |
|
import javax.servlet.*; |
| 16 |
|
import javax.servlet.http.HttpServletRequest; |
| 17 |
|
import javax.servlet.http.HttpServletResponse; |
| 18 |
|
import java.io.IOException; |
| 19 |
|
|
| 20 |
|
|
| 21 |
|
@deprecated |
| 22 |
|
|
|
|
|
| 0% |
Uncovered Elements: 31 (31) |
Complexity: 10 |
Complexity Density: 0.5 |
|
| 23 |
|
public abstract class GzipFilter extends AbstractFilter |
| 24 |
|
{ |
| 25 |
|
private static final Category log = Category.getInstance(GzipFilter.class); |
| 26 |
|
private static final String ALREADY_FILTERED = GzipFilter.class.getName() + "_already_filtered"; |
| 27 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 28 |
0
|
public void init(FilterConfig filterConfig) throws ServletException... |
| 29 |
|
{ |
| 30 |
0
|
super.init(filterConfig); |
| 31 |
|
} |
| 32 |
|
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 6 |
Complexity Density: 0.38 |
|
| 33 |
0
|
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException... |
| 34 |
|
{ |
| 35 |
0
|
if (req.getAttribute(ALREADY_FILTERED) != null) |
| 36 |
|
{ |
| 37 |
0
|
chain.doFilter(req, res); |
| 38 |
0
|
return; |
| 39 |
|
} |
| 40 |
|
else |
| 41 |
|
{ |
| 42 |
0
|
req.setAttribute(ALREADY_FILTERED, Boolean.TRUE); |
| 43 |
|
} |
| 44 |
|
|
| 45 |
0
|
if (req instanceof HttpServletRequest && useGzipForThisRequest((HttpServletRequest) req)) |
| 46 |
|
{ |
| 47 |
0
|
HttpServletRequest request = (HttpServletRequest) req; |
| 48 |
0
|
HttpServletResponse response = (HttpServletResponse) res; |
| 49 |
0
|
String ae = request.getHeader("accept-encoding"); |
| 50 |
0
|
if (ae != null && ae.indexOf("gzip") != -1 ) |
| 51 |
|
{ |
| 52 |
0
|
log.debug("GZIP supported, compressing."); |
| 53 |
|
|
| 54 |
0
|
GzipResponseWrapper wrappedResponse = new GzipResponseWrapper(response, getEncoding()); |
| 55 |
0
|
chain.doFilter(req, wrappedResponse); |
| 56 |
0
|
wrappedResponse.finishResponse(); |
| 57 |
0
|
return; |
| 58 |
|
} |
| 59 |
0
|
chain.doFilter(req, res); |
| 60 |
|
} |
| 61 |
|
else |
| 62 |
|
{ |
| 63 |
0
|
chain.doFilter(req, res); |
| 64 |
|
} |
| 65 |
|
} |
| 66 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 67 |
0
|
protected boolean useGzipForThisRequest(HttpServletRequest req)... |
| 68 |
|
{ |
| 69 |
0
|
return (useGzip() && !isStyleSheet(req) && isTopLevelRequest(req)); |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
protected abstract boolean useGzip(); |
| 73 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 74 |
0
|
protected boolean isTopLevelRequest(HttpServletRequest request)... |
| 75 |
|
{ |
| 76 |
0
|
return request.getAttribute("javax.servlet.include.servlet_path") == null; |
| 77 |
|
} |
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 82 |
0
|
protected boolean isStyleSheet(HttpServletRequest request)... |
| 83 |
|
{ |
| 84 |
0
|
return request.getServletPath() != null && request.getServletPath().indexOf("css") != -1; |
| 85 |
|
} |
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
|
|
| 90 |
|
@return |
| 91 |
|
|
| 92 |
|
protected abstract String getEncoding(); |
| 93 |
|
} |