use of org.eclipse.jetty.servlets.gzip.GzipHandler in project knox by apache.
the class GatewayServer method createHandlers.
private static HandlerCollection createHandlers(final GatewayConfig config, final GatewayServices services, final ContextHandlerCollection contexts, final Map<String, Integer> topologyPortMap) {
HandlerCollection handlers = new HandlerCollection();
RequestLogHandler logHandler = new RequestLogHandler();
logHandler.setRequestLog(new AccessHandler());
TraceHandler traceHandler = new TraceHandler();
traceHandler.setHandler(contexts);
traceHandler.setTracedBodyFilter(System.getProperty("org.apache.knox.gateway.trace.body.status.filter"));
CorrelationHandler correlationHandler = new CorrelationHandler();
correlationHandler.setHandler(traceHandler);
/* KNOX-732: Handler for GZip compression */
GzipHandler gzipHandler = new GzipHandler();
String[] mimeTypes = {};
if (config.getMimeTypesToCompress() != null && !config.getMimeTypesToCompress().isEmpty()) {
mimeTypes = (String[]) config.getMimeTypesToCompress().toArray();
}
gzipHandler.addIncludedMimeTypes(mimeTypes);
gzipHandler.setHandler(correlationHandler);
// Used to correct the {target} part of request with Topology Port Mapping feature
final PortMappingHelperHandler portMappingHandler = new PortMappingHelperHandler(config);
portMappingHandler.setHandler(gzipHandler);
if (config.isGatewayPortMappingEnabled()) {
for (final Map.Entry<String, Integer> entry : topologyPortMap.entrySet()) {
log.createJettyHandler(entry.getKey());
final ContextHandler topologyContextHandler = new ContextHandler();
final RequestUpdateHandler updateHandler = new RequestUpdateHandler(config, entry.getKey(), services);
topologyContextHandler.setHandler(updateHandler);
topologyContextHandler.setVirtualHosts(new String[] { "@" + entry.getKey().toLowerCase() });
handlers.addHandler(topologyContextHandler);
}
}
handlers.addHandler(logHandler);
if (config.isWebsocketEnabled()) {
final GatewayWebsocketHandler websocketHandler = new GatewayWebsocketHandler(config, services);
websocketHandler.setHandler(portMappingHandler);
handlers.addHandler(websocketHandler);
} else {
handlers.addHandler(portMappingHandler);
}
return handlers;
}
use of org.eclipse.jetty.servlets.gzip.GzipHandler in project gocd by gocd.
the class Jetty9Server method gzipHandler.
static GzipHandler gzipHandler(Handler handler) {
GzipHandler gzipHandler = new GzipHandler();
gzipHandler.addIncludedMimeTypes("application/javascript", "application/json", "application/vnd.go.cd.v1+json", "application/vnd.go.cd.v2+json", "application/vnd.go.cd.v3+json", "application/vnd.go.cd.v4+json", "application/vnd.go.cd.v5+json", "application/vnd.go.cd.v6+json", "application/vnd.go.cd.v7+json", "application/vnd.go.cd.v8+json", "application/vnd.go.cd.v9+json", "application/xhtml+xml", "image/svg+xml", "text/css", "text/html", "text/plain", "text/xml");
gzipHandler.addIncludedMethods("HEAD", "GET", "POST", "PUT", "PATCH", "DELETE");
gzipHandler.setHandler(handler);
return gzipHandler;
}
Aggregations