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; }
gzipHandler.setHandler(context); gzipHandler.addIncludedMethods(HttpMethod.POST); gzipHandler.addIncludedMimeTypes(APPLICATION_THRIFT); server.setHandler(gzipHandler); } else {
private HandlerCollection createHandlers() { final WebAppContext webApp = new WebAppContext(); webApp.setContextPath(contextPath); webApp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false"); webApp.getSessionHandler().setMaxInactiveInterval(sessionTimeout * 60); // GZIP handler final GzipHandler gzipHandler = new GzipHandler(); gzipHandler.addIncludedMimeTypes("text/html", "text/xml", "text/css", "text/plain", "text/javascript", "application/javascript", "application/json", "application/xml"); gzipHandler.setIncludedMethods("GET", "POST"); gzipHandler.setCompressionLevel(9); gzipHandler.setHandler(webApp); if (Strings.isNullOrEmpty(webAppLocation)) { webApp.setWar(getShadedWarUrl()); } else { webApp.setWar(webAppLocation); } // Request log handler final RequestLogHandler log = new RequestLogHandler(); log.setRequestLog(createRequestLog()); // Redirect root context handler MovedContextHandler rootRedirect = new MovedContextHandler(); rootRedirect.setContextPath("/"); rootRedirect.setNewContextURL(contextPath); rootRedirect.setPermanent(true); // Put rootRedirect at the end! return new HandlerCollection(log, gzipHandler, rootRedirect); }
/** * Creates a Jetter Handler associated with a Web Context. * * @param context The Web Application Context to associate with the Handler. * * @return A Handler that can handle Web Requests to this Jetty Server. */ private static Handler getServletContextHandler(WebApplicationContext context, RepositoryProvider repoProvider) { ServletContextHandler contextHandler = new ServletContextHandler(); // gzip handler GzipHandler gzipHandler = new GzipHandler(); gzipHandler.addIncludedMimeTypes( MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE); contextHandler.setGzipHandler(gzipHandler); //contextHandler.setErrorHandler(null); contextHandler.setContextPath("/"); ServletHolder servletHolder = new ServletHolder(new DispatcherServlet(context)); // configure the Servlet with Multipart support, just use defaults for now servletHolder.getRegistration().setMultipartConfig(new MultipartConfigElement((String)null)); contextHandler.addServlet(servletHolder, "/"); contextHandler.addEventListener(new ContextLoaderListener(context)); // wrap it with our RequestHandler that inserts the repoProvider into the request attributes return new RequestHandlerWrapper(contextHandler, repoProvider); }
gzipHandler.setHandler(context); gzipHandler.addIncludedMethods(HttpMethod.POST); gzipHandler.addIncludedMimeTypes(APPLICATION_THRIFT); server.setHandler(gzipHandler); } else {
gzipHandler.addIncludedPaths(this.config.getGzipIncludedPaths()); gzipHandler.addExcludedPaths(this.config.getGzipExcludedPaths()); gzipHandler.addIncludedMimeTypes(this.config.getGzipIncludedMimeTypes()); gzipHandler.addExcludedMimeTypes(this.config.getGzipExcludedMimeTypes());