diff --git a/pom.xml b/pom.xml index 03dd13e..6c842c4 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ io.jooby jooby-maven-plugin - 3.9.1 + 4.0.6 maven-shade-plugin @@ -71,14 +71,14 @@ io.jooby jooby-bom - 3.9.1 + 4.0.6 pom import software.amazon.awssdk bom - 2.31.71 + 2.32.29 pom import @@ -94,17 +94,17 @@ org.apache.logging.log4j log4j-core - 2.25.0 + 2.25.1 org.apache.logging.log4j log4j-slf4j2-impl - 2.25.0 + 2.25.1 org.apache.logging.log4j log4j-iostreams - 2.25.0 + 2.25.1 com.lmax @@ -125,7 +125,7 @@ com.github.ben-manes.caffeine caffeine - 3.2.1 + 3.2.2 @@ -136,7 +136,7 @@ org.xerial sqlite-jdbc - 3.50.1.0 + 3.50.3.0 diff --git a/src/main/java/me/lucko/bytebin/Bytebin.java b/src/main/java/me/lucko/bytebin/Bytebin.java index 8b3eba9..bbed9ff 100644 --- a/src/main/java/me/lucko/bytebin/Bytebin.java +++ b/src/main/java/me/lucko/bytebin/Bytebin.java @@ -29,6 +29,9 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder; import io.jooby.ExecutionMode; import io.jooby.Jooby; +import io.jooby.Server; +import io.jooby.ServerOptions; +import io.jooby.jetty.JettyServer; import io.prometheus.client.hotspot.DefaultExports; import me.lucko.bytebin.content.Content; import me.lucko.bytebin.content.ContentIndexDatabase; @@ -98,7 +101,7 @@ public static void main(String[] args) throws Exception { private final LogHandler logHandler; /** The web server instance */ - private final BytebinServer server; + private final Server server; public Bytebin(Configuration config) throws Exception { // setup simple logger @@ -160,13 +163,20 @@ public Bytebin(Configuration config) throws Exception { ? new HttpLogHandler(loggingHttpUri, config.getInt(Option.LOGGING_HTTP_FLUSH_PERIOD, 10)) : new LogHandler.Stub(); + long maxContentLength = Content.MEGABYTE_LENGTH * config.getInt(Option.MAX_CONTENT_LENGTH, 10); + // setup the web server - this.server = (BytebinServer) Jooby.createApp(ExecutionMode.EVENT_LOOP, () -> new BytebinServer( + ServerOptions serverOpts = new ServerOptions(); + serverOpts.setHost(config.getString(Option.HOST, "0.0.0.0")); + serverOpts.setPort(config.getInt(Option.PORT, 8080)); + serverOpts.setCompressionLevel(null); + serverOpts.setMaxRequestSize((int) maxContentLength); + + this.server = new JettyServer(serverOpts); + this.server.start(Jooby.createApp(this.server, ExecutionMode.EVENT_LOOP, () -> new BytebinServer( storageHandler, contentLoader, this.logHandler, - config.getString(Option.HOST, "0.0.0.0"), - config.getInt(Option.PORT, 8080), metrics, new RateLimitHandler(config.getStringList(Option.RATELIMIT_API_KEYS)), new RateLimiter( @@ -185,12 +195,11 @@ public Bytebin(Configuration config) throws Exception { config.getInt(Option.READ_RATE_LIMIT, 30) ), new TokenGenerator(config.getInt(Option.KEY_LENGTH, 7)), - (Content.MEGABYTE_LENGTH * config.getInt(Option.MAX_CONTENT_LENGTH, 10)), + maxContentLength, expiryHandler, config.getStringMap(Option.HTTP_HOST_ALIASES), ImmutableSet.copyOf(config.getStringList(Option.ADMIN_API_KEYS)) - )); - this.server.start(); + ))); // schedule invalidation task if (expiryHandler.hasExpiryTimes() || metrics) { diff --git a/src/main/java/me/lucko/bytebin/http/BytebinServer.java b/src/main/java/me/lucko/bytebin/http/BytebinServer.java index 0d690ae..472c700 100644 --- a/src/main/java/me/lucko/bytebin/http/BytebinServer.java +++ b/src/main/java/me/lucko/bytebin/http/BytebinServer.java @@ -26,11 +26,10 @@ package me.lucko.bytebin.http; import io.jooby.Context; -import io.jooby.ExecutionMode; import io.jooby.Jooby; import io.jooby.MediaType; import io.jooby.ReactiveSupport; -import io.jooby.ServerOptions; +import io.jooby.RouterOptions; import io.jooby.StatusCode; import io.jooby.exception.StatusCodeException; import io.jooby.handler.AssetHandler; @@ -67,16 +66,8 @@ public class BytebinServer extends Jooby { .labelNames("method", "useragent") .register(); - public BytebinServer(ContentStorageHandler storageHandler, ContentLoader contentLoader, LogHandler logHandler, String host, int port, boolean metrics, RateLimitHandler rateLimitHandler, RateLimiter postRateLimiter, RateLimiter putRateLimiter, RateLimiter readRateLimiter, TokenGenerator contentTokenGenerator, long maxContentLength, ExpiryHandler expiryHandler, Map hostAliases, Set adminApiKeys) { - ServerOptions serverOpts = new ServerOptions(); - serverOpts.setHost(host); - serverOpts.setPort(port); - serverOpts.setCompressionLevel(null); - serverOpts.setMaxRequestSize((int) maxContentLength); - setServerOptions(serverOpts); - - setExecutionMode(ExecutionMode.EVENT_LOOP); - setTrustProxy(true); + public BytebinServer(ContentStorageHandler storageHandler, ContentLoader contentLoader, LogHandler logHandler, boolean metrics, RateLimitHandler rateLimitHandler, RateLimiter postRateLimiter, RateLimiter putRateLimiter, RateLimiter readRateLimiter, TokenGenerator contentTokenGenerator, long maxContentLength, ExpiryHandler expiryHandler, Map hostAliases, Set adminApiKeys) { + setRouterOptions(new RouterOptions().setTrustProxy(true)); use(ReactiveSupport.concurrent());