public static GzipHandler wrapWithDefaultGzipHandler(final Handler handler, int inflateBufferSize, int compressionLevel) { GzipHandler gzipHandler = new GzipHandler(); gzipHandler.setMinGzipSize(0); gzipHandler.setIncludedMethods(GZIP_METHODS); gzipHandler.setInflateBufferSize(inflateBufferSize); gzipHandler.setCompressionLevel(compressionLevel); // We don't actually have any precomputed .gz resources, and checking for them inside jars is expensive. gzipHandler.setCheckGzExists(false); gzipHandler.setHandler(handler); return gzipHandler; }
/** * Enables compression for the specified handler. * * @param handler handler to enable compression for * @return compression enabled handler */ private Handler gzip(final Handler handler) { final GzipHandler gzip = new GzipHandler(); gzip.setIncludedMethods("GET", "POST", "PUT", "DELETE"); gzip.setHandler(handler); return gzip; }
static GzipHandler gzipHandler() { 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"); return gzipHandler; }
public GzipHandler build(@Nullable Handler handler) { final GzipHandler gzipHandler = new GzipHandler(); gzipHandler.setHandler(handler); gzipHandler.setMinGzipSize((int) minimumEntitySize.toBytes()); gzipHandler.setInflateBufferSize((int) bufferSize.toBytes()); gzipHandler.setCompressionLevel(deflateCompressionLevel); gzipHandler.setSyncFlush(syncFlush); gzipHandler.setIncludedMimeTypes(compressedMimeTypes.toArray(new String[0])); gzipHandler.setExcludedMimeTypes(excludedMimeTypes.toArray(new String[0])); gzipHandler.setIncludedMethods(includedMethods.toArray(new String[0])); gzipHandler.setExcludedPaths(excludedPaths.toArray(new String[0])); gzipHandler.setIncludedPaths(includedPaths.toArray(new String[0])); gzipHandler.setExcludedAgentPatterns(excludedUserAgentPatterns.toArray(new String[0]));
public static void main(String[] args) throws Exception { WebAppMain.standAloneMode = true; Logo.print(true); initializeLogDir(); final ConfigureAdaptor conf = ConfigureManager.getConfigure(); connectScouterCollector(); final Server server = new Server(conf.getNetHttpPort()); HandlerCollection handlers = new HandlerCollection(); RequestLogHandler requestLogHandler = setRequestLogHandler(); handlers.addHandler(requestLogHandler); ServletContextHandler servletContextHandler = setWebAppContext(); if (conf.isNetHttpApiGzipEnabled()) { GzipHandler gzipHandler = new GzipHandler(); gzipHandler.setIncludedMethods("GET", "POST", "PUT", "DELETE"); gzipHandler.setMinGzipSize(1024); gzipHandler.setHandler(servletContextHandler); handlers.addHandler(gzipHandler); } else { handlers.addHandler(servletContextHandler); } server.setHandler(handlers); setWebSocketServer(servletContextHandler); try { server.start(); waitOnExit(server); } catch (Exception e) { e.printStackTrace(); } }
GzipHandler gzipHandler = new GzipHandler(); gzipHandler.setIncludedMimeTypes("application/json"); gzipHandler.addIncludedMethods("GET","POST"); gzipHandler.setIncludedPaths("/*"); gzipHandler.setHandler(servletContextHandler);
final GzipHandler gzipHandler = new GzipHandler(); gzipHandler.setHandler(context); gzipHandler.addIncludedMethods(HttpMethod.POST); gzipHandler.addIncludedMimeTypes(APPLICATION_THRIFT); server.setHandler(gzipHandler); } else {
@Override public AbstractHandler configureHandler() throws Exception { GzipHandler gzipHandler = new GzipHandler(); gzipHandler.setHandler(new StreamHandler()); return gzipHandler; }
static HandlerWrapper createGzipHandlerWrapper(Compression compression) { GzipHandler handler = new GzipHandler(); handler.setMinGzipSize((int) compression.getMinResponseSize().toBytes()); handler.setIncludedMimeTypes(compression.getMimeTypes()); for (HttpMethod httpMethod : HttpMethod.values()) { handler.addIncludedMethods(httpMethod.name()); } if (compression.getExcludedUserAgents() != null) { handler.setExcludedAgentPatterns(compression.getExcludedUserAgents()); } return handler; }
@Signature public void __construct() { gzipHandler = new GzipHandler(); }
public AssetsContextHandler(SystemEnvironment systemEnvironment) { super(systemEnvironment.getWebappContextPath() + "/assets"); this.systemEnvironment = systemEnvironment; handler = new AssetsHandler(); GzipHandler gzipHandler = Jetty9Server.gzipHandler(); gzipHandler.setHandler(this.handler); setHandler(gzipHandler); }
@Signature public void minGzipSize(int size) { gzipHandler.setMinGzipSize(size); }
@Signature public void includeMimeTypes(String[] mimeTypes) { gzipHandler.setIncludedMimeTypes(mimeTypes); }
@Signature public void compressLevel(int level) { gzipHandler.setCompressionLevel(level); }
gzipHandler.addIncludedPaths("/*"); gzipHandler.addIncludedMethods(HttpMethod.POST.asString());
@Signature public void excludeMethods(String[] methods) { gzipHandler.setExcludedMethods(methods); }
@Signature public void excludeMimeTypes(String[] mimeTypes) { gzipHandler.setExcludedMimeTypes(mimeTypes); }
@Signature public void __invoke(PHttpServerRequest request, PHttpServerResponse response) throws IOException, ServletException { Request baseRequest = Request.getBaseRequest(request.getRequest()); gzipHandler.handle(request.getRequest().getRequestURI(), baseRequest, request.getRequest(), response.getResponse()); } }
GzipHandler gzipHandler = new GzipHandler(); gzipHandler.setIncludedMethods("GET", "POST", "PUT", "DELETE"); gzipHandler.setMinGzipSize(1024); gzipHandler.setHandler(context); handlers.addHandler(gzipHandler); } else {
@Signature public void includeMethods(String[] methods) { gzipHandler.setExcludedMethods(methods); }