use of io.undertow.server.handlers.RequestBufferingHandler in project adeptj-runtime by AdeptJ.
the class Server method rootHandler.
/**
* Chaining of Undertow {@link HttpHandler} instances as follows.
* <p>
* 1. GracefulShutdownHandler
* 2. RequestLimitingHandler
* 3. AllowedMethodsHandler
* 4. PredicateHandler which resolves to either RedirectHandler or SetHeadersHandler
* 5. RequestBufferingHandler if request buffering is enabled, wrapped in SetHeadersHandler
* 5. And Finally ServletInitialHandler
*
* @param servletInitialHandler the {@link io.undertow.servlet.handlers.ServletInitialHandler}
* @return GracefulShutdownHandler as the root handler
*/
private GracefulShutdownHandler rootHandler(HttpHandler servletInitialHandler) {
Config cfg = Objects.requireNonNull(this.cfgReference.get());
Map<HttpString, String> headers = new HashMap<>();
headers.put(HttpString.tryFromString(HEADER_SERVER), cfg.getString(KEY_HEADER_SERVER));
if (Environment.isDev()) {
headers.put(HttpString.tryFromString(HEADER_X_POWERED_BY), Version.getFullVersionString());
}
HttpHandler headersHandler = Boolean.getBoolean(SYS_PROP_ENABLE_REQ_BUFF) ? new SetHeadersHandler(new RequestBufferingHandler(servletInitialHandler, Integer.getInteger(SYS_PROP_REQ_BUFF_MAX_BUFFERS, cfg.getInt(KEY_REQ_BUFF_MAX_BUFFERS))), headers) : new SetHeadersHandler(servletInitialHandler, headers);
return Handlers.gracefulShutdown(new RequestLimitingHandler(Integer.getInteger(SYS_PROP_MAX_CONCUR_REQ, cfg.getInt(KEY_MAX_CONCURRENT_REQS)), new AllowedMethodsHandler(Handlers.predicate(exchange -> CONTEXT_PATH.equals(exchange.getRequestURI()), Handlers.redirect(TOOLS_DASHBOARD_URI), headersHandler), this.allowedMethods(cfg))));
}
Aggregations