Joaquín Reñé
2025-10-07 146a0fb8b0e90f9196e569152f649baf60d6cc8f
securis/src/main/java/net/curisit/securis/GzipFilter.java
....@@ -1,3 +1,6 @@
1
+/*
2
+ * Copyright @ 2013 CurisTEC, S.A.S. All Rights Reserved.
3
+ */
14 package net.curisit.securis;
25
36 import java.io.IOException;
....@@ -18,6 +21,12 @@
1821
1922 import net.curisit.securis.utils.GZipServletResponseWrapper;
2023
24
+/**
25
+* GzipFilter
26
+* <p>
27
+* Servlet filter that compresses <code>*.js</code> responses with GZIP when the client
28
+* advertises <code>Accept-Encoding: gzip</code>.
29
+*/
2130 @ApplicationScoped
2231 @WebFilter(urlPatterns = "*.js")
2332 public class GzipFilter implements Filter {
....@@ -25,10 +34,16 @@
2534 @SuppressWarnings("unused")
2635 private static final Logger LOG = LogManager.getLogger(GzipFilter.class);
2736
37
+ /** init<p>Filter init hook (unused). */
2838 @Override
2939 public void init(FilterConfig fc) throws ServletException {
3040 }
3141
42
+ /**
43
+ * doFilter
44
+ * <p>
45
+ * Wrap the response with a GZIP-compressing wrapper if supported by the client.
46
+ */
3247 @Override
3348 public void doFilter(ServletRequest sreq, ServletResponse sres, FilterChain chain) throws IOException, ServletException {
3449 HttpServletRequest httpRequest = (HttpServletRequest) sreq;
....@@ -44,12 +59,18 @@
4459 }
4560 }
4661
62
+ /**
63
+ * acceptsGZipEncoding
64
+ * <p>
65
+ * @return {@code true} when request header contains "gzip" in <code>Accept-Encoding</code>.
66
+ */
4767 private boolean acceptsGZipEncoding(HttpServletRequest httpRequest) {
4868 String acceptEncoding = httpRequest.getHeader("Accept-Encoding");
4969
5070 return acceptEncoding != null && acceptEncoding.indexOf("gzip") != -1;
5171 }
5272
73
+ /** destroy<p>Filter destroy hook (unused). */
5374 @Override
5475 public void destroy() {
5576 }