/*
 * Druid - a distributed column store.
 * Copyright (C) 2014  Metamarkets Group Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package io.druid.server.initialization;

import com.google.common.base.Joiner;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlets.AsyncGzipFilter;
import org.eclipse.jetty.servlets.GzipFilter;

import javax.ws.rs.HttpMethod;

public abstract class BaseJettyServerInitializer implements JettyServerInitializer
{

  public static final String GZIP_METHODS = Joiner.on(",").join(HttpMethod.GET, HttpMethod.POST);

  public FilterHolder defaultGzipFilterHolder() {
    final FilterHolder gzipFilterHolder = new FilterHolder(GzipFilter.class);
    gzipFilterHolder.setInitParameter("minGzipSize", "0");
    gzipFilterHolder.setInitParameter("methods", GZIP_METHODS);
    return gzipFilterHolder;
  }

  public FilterHolder defaultAsyncGzipFilterHolder() {
    final FilterHolder gzipFilterHolder = new FilterHolder(AsyncGzipFilter.class);
    gzipFilterHolder.setInitParameter("minGzipSize", "0");
    gzipFilterHolder.setInitParameter("methods", GZIP_METHODS);
    return gzipFilterHolder;
  }
}

@@ -1288,32 +1288,34 @@
 ipFilterHolder()
+%0A 
  %7B%0A    final Fil
@@ -1375,33 +1375,43 @@
 ter.class);%0A    
-g
+setDefaultG
 zipFilterHolder.
@@ -1405,32 +1405,24 @@
 FilterHolder
-.setInit
 Parameter(%22m
@@ -1422,91 +1422,26 @@
 eter
-(%22minGzipSize%22, %220%22);%0A    gzipFilterHolder.setInitParameter(%22methods%22, GZIP_METHODS
+s(gzipFilterHolder
 );%0A 
@@ -1525,16 +1525,18 @@
 Holder()
+%0A 
  %7B%0A    f
@@ -1613,29 +1613,215 @@
 class);%0A    
-gzipF
+setDefaultGzipFilterHolderParameters(gzipFilterHolder);%0A    return gzipFilterHolder;%0A  %7D%0A%0A  private static void setDefaultGzipFilterHolderParameters(final FilterHolder filterHolder)%0A  %7B%0A    f
 ilterHolder.
@@ -1862,21 +1862,17 @@
 %22);%0A    
-gzipF
+f
 ilterHol
@@ -1922,35 +1922,191 @@
 S);%0A
+%0A
     
-return gzipFilterHolder
+// We don't actually have any precomputed .gz resources, and checking for them inside jars is expensive.%0A    filterHolder.setInitParameter(%22checkGzExists%22, String.valueOf(false))
 ;%0A  

Disable checkGzExists in the default GzipFilter.