Coverage Report - org.apache.tapestry5.internal.gzip.GZipFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
GZipFilter
100%
6/6
100%
2/2
0
 
 1  
 // Copyright 2009 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry5.internal.gzip;
 16  
 
 17  
 import org.apache.tapestry5.SymbolConstants;
 18  
 import org.apache.tapestry5.ioc.annotations.Symbol;
 19  
 import org.apache.tapestry5.services.HttpServletRequestFilter;
 20  
 import org.apache.tapestry5.services.HttpServletRequestHandler;
 21  
 import org.apache.tapestry5.services.ResponseCompressionAnalyzer;
 22  
 
 23  
 import javax.servlet.http.HttpServletRequest;
 24  
 import javax.servlet.http.HttpServletResponse;
 25  
 import java.io.IOException;
 26  
 
 27  
 /**
 28  
  * Filter that adds GZIP compression to the response, if the client supports it.
 29  
  */
 30  
 public class GZipFilter implements HttpServletRequestFilter
 31  
 {
 32  
     private final int cutover;
 33  
 
 34  
     private final ResponseCompressionAnalyzer analyzer;
 35  
 
 36  
     public GZipFilter(
 37  
             @Symbol(SymbolConstants.MIN_GZIP_SIZE)
 38  
             int cutover,
 39  
 
 40  
             ResponseCompressionAnalyzer analyzer)
 41  10
     {
 42  10
         this.cutover = cutover;
 43  10
         this.analyzer = analyzer;
 44  10
     }
 45  
 
 46  
     public boolean service(HttpServletRequest request, HttpServletResponse response, HttpServletRequestHandler handler)
 47  
             throws IOException
 48  
     {
 49  1560
         HttpServletResponse newResponse = analyzer.isGZipSupported()
 50  
                                           ? new GZIPEnabledResponse(response, request, cutover, analyzer)
 51  
                                           : response;
 52  
 
 53  1560
         return handler.service(request, newResponse);
 54  
     }
 55  
 }