Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<plugin>
<groupId>io.jooby</groupId>
<artifactId>jooby-maven-plugin</artifactId>
<version>3.9.1</version>
<version>4.0.6</version>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
Expand Down Expand Up @@ -71,14 +71,14 @@
<dependency>
<groupId>io.jooby</groupId>
<artifactId>jooby-bom</artifactId>
<version>3.9.1</version>
<version>4.0.6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.31.71</version>
<version>2.32.29</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -94,17 +94,17 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.25.0</version>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<version>2.25.0</version>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-iostreams</artifactId>
<version>2.25.0</version>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>com.lmax</groupId>
Expand All @@ -125,7 +125,7 @@
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>3.2.1</version>
<version>3.2.2</version>
</dependency>

<dependency>
Expand All @@ -136,7 +136,7 @@
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.50.1.0</version>
<version>3.50.3.0</version>
</dependency>

<dependency>
Expand Down
23 changes: 16 additions & 7 deletions src/main/java/me/lucko/bytebin/Bytebin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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) {
Expand Down
15 changes: 3 additions & 12 deletions src/main/java/me/lucko/bytebin/http/BytebinServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> hostAliases, Set<String> 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<String, String> hostAliases, Set<String> adminApiKeys) {
setRouterOptions(new RouterOptions().setTrustProxy(true));

use(ReactiveSupport.concurrent());

Expand Down