Skip to content

Commit

Permalink
Merge pull request flipkart-incubator#99 from flipkart-incubator/gzip-5
Browse files Browse the repository at this point in the history
Moving to Jetty GzipHandler
  • Loading branch information
pmohankumar authored Feb 28, 2017
2 parents d85402e + 0c6dba0 commit 46acc88
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions container/src/main/java/com/flipkart/poseidon/Poseidon.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.RequestLogHandler;
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
Expand Down Expand Up @@ -160,12 +161,20 @@ public void start() {
private HandlerCollection getHandlers() {
ContextHandlerCollection contextHandlerCollection = new ContextHandlerCollection();
contextHandlerCollection.setHandlers(new Handler[]{
getRequestLogHandler(getParentHandler()),
getRequestLogHandler(getGzipHandler(getParentHandler())),
getMetricsHandler()
});
return contextHandlerCollection;
}

private Handler getGzipHandler(Handler handler) {
GzipHandler gzipHandler = new GzipHandler();
gzipHandler.addIncludedMethods("GET", "POST", "PUT", "DELETE", "PATCH");
gzipHandler.addIncludedPaths("/*");
gzipHandler.setHandler(handler);
return gzipHandler;
}

private Handler getRequestLogHandler(Handler handler) {
RequestLog requestLog = new Log4JAccessLog(configuration.getAccessLogConfigFilePath(),
() -> configuration.isAccessLogEnabled());
Expand Down Expand Up @@ -256,7 +265,6 @@ private void addFilters(ServletContextHandler servletContextHandler) {
servletContextHandler.addFilter(new FilterHolder(servletTraceFilter), "/*", EnumSet.of(REQUEST));
}
servletContextHandler.addFilter(new FilterHolder(new RequestGzipFilter()), "/*", EnumSet.of(REQUEST));
servletContextHandler.addFilter(getGzipFilter(), "/*", EnumSet.of(REQUEST));

List<JettyFilterConfiguration> jettyFilterConfigurations = Optional.ofNullable(configuration.getJettyConfiguration()).map(JettyConfiguration::getJettyFilterConfigurations).orElse(new ArrayList<>());
for (JettyFilterConfiguration filterConfig : jettyFilterConfigurations) {
Expand All @@ -268,15 +276,6 @@ private void addFilters(ServletContextHandler servletContextHandler) {
}
}

/*
* Jetty9 GzipFilter, by default, enables compressing of response only for GET requests.
*/
private FilterHolder getGzipFilter() {
FilterHolder gzipFilterHolder = new FilterHolder(new GzipFilter());
gzipFilterHolder.setInitParameter("methods", "GET,POST,PUT,DELETE,PATCH");
return gzipFilterHolder;
}

private PoseidonServlet getPoseidonServlet() {
return new PoseidonServlet(application, configuration);
}
Expand Down

0 comments on commit 46acc88

Please sign in to comment.