diff --git a/gradle.properties b/gradle.properties index dda048ab1..6872dee33 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ neoforge_version=21.1.42 parchment_mc_version=1.21 parchment_mapping_version=2024.07.28 rhino_version=2101.2.5-build.54 -tiny_server_version=1.0.0-build.6 +tiny_server_version=1.0.0-build.15 gif_lib_version=1.7 architectury_version=13.0.6 diff --git a/src/main/java/dev/latvian/mods/kubejs/web/JsonContent.java b/src/main/java/dev/latvian/mods/kubejs/web/JsonContent.java index c474c54f4..25b1a8b73 100644 --- a/src/main/java/dev/latvian/mods/kubejs/web/JsonContent.java +++ b/src/main/java/dev/latvian/mods/kubejs/web/JsonContent.java @@ -6,6 +6,7 @@ import dev.latvian.apps.tinyserver.content.ResponseContent; import dev.latvian.mods.kubejs.util.Lazy; +import java.io.IOException; import java.io.OutputStream; import java.nio.charset.StandardCharsets; import java.util.function.Consumer; @@ -43,7 +44,7 @@ public String type() { } @Override - public void write(OutputStream out) throws Exception { + public void write(OutputStream out) throws IOException { out.write(json.get()); } } diff --git a/src/main/java/dev/latvian/mods/kubejs/web/LocalWebServer.java b/src/main/java/dev/latvian/mods/kubejs/web/LocalWebServer.java index 9a8fb5b65..544239945 100644 --- a/src/main/java/dev/latvian/mods/kubejs/web/LocalWebServer.java +++ b/src/main/java/dev/latvian/mods/kubejs/web/LocalWebServer.java @@ -14,6 +14,8 @@ import java.util.List; public record LocalWebServer(HTTPServer server, String url, List endpoints) { + public static final String SERVER_NAME = "KubeJS " + KubeJS.VERSION; + public record Endpoint(String method, String path) implements Comparable { @Override public int compareTo(@NotNull LocalWebServer.Endpoint o) { @@ -37,10 +39,11 @@ public static void start(BlockableEventLoop eventLoop) { var publicAddress = WebServerProperties.get().publicAddress; registry.server.setDaemon(true); - registry.server.setServerName("KubeJS " + KubeJS.VERSION); + registry.server.setServerName(SERVER_NAME); registry.server.setAddress(publicAddress.isEmpty() ? "127.0.0.1" : "0.0.0.0"); registry.server.setPort(WebServerProperties.get().port); registry.server.setMaxPortShift(10); + registry.server.setMaxKeepAliveConnections(3); var url = "http://localhost:" + registry.server.start(); KubeJS.LOGGER.info("Started the local web server at " + url); diff --git a/src/main/java/dev/latvian/mods/kubejs/web/local/KubeJSWeb.java b/src/main/java/dev/latvian/mods/kubejs/web/local/KubeJSWeb.java index 5015023ce..a16b28583 100644 --- a/src/main/java/dev/latvian/mods/kubejs/web/local/KubeJSWeb.java +++ b/src/main/java/dev/latvian/mods/kubejs/web/local/KubeJSWeb.java @@ -3,6 +3,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import dev.latvian.apps.tinyserver.ServerRegistry; +import dev.latvian.apps.tinyserver.http.response.HTTPPayload; import dev.latvian.apps.tinyserver.http.response.HTTPResponse; import dev.latvian.apps.tinyserver.http.response.HTTPStatus; import dev.latvian.apps.tinyserver.ws.Frame; @@ -129,6 +130,7 @@ private static void reloadInternalServer() { private static HTTPResponse getHomepage(KJSHTTPRequest req) { var list = new ArrayList(); list.add("KubeJS Local Web Server [" + KubeJS.PROXY.getWebServerWindowTitle() + "]"); + list.add(HTTPPayload.DATE_TIME_FORMATTER.format(req.startTime())); list.add(""); list.add("Loaded Plugins:"); diff --git a/src/main/java/dev/latvian/mods/kubejs/web/local/client/ImageGenerator.java b/src/main/java/dev/latvian/mods/kubejs/web/local/client/ImageGenerator.java index 90a31519b..65dd8b161 100644 --- a/src/main/java/dev/latvian/mods/kubejs/web/local/client/ImageGenerator.java +++ b/src/main/java/dev/latvian/mods/kubejs/web/local/client/ImageGenerator.java @@ -11,8 +11,8 @@ import com.mojang.blaze3d.vertex.VertexFormat; import com.mojang.blaze3d.vertex.VertexSorting; import dev.latvian.apps.tinyserver.content.ResponseContent; +import dev.latvian.apps.tinyserver.http.response.HTTPPayload; import dev.latvian.apps.tinyserver.http.response.HTTPResponse; -import dev.latvian.apps.tinyserver.http.response.HTTPResponseBuilder; import dev.latvian.apps.tinyserver.http.response.HTTPStatus; import dev.latvian.mods.kubejs.KubeJS; import dev.latvian.mods.kubejs.KubeJSPaths; @@ -22,6 +22,7 @@ import dev.latvian.mods.kubejs.util.CachedComponentObject; import dev.latvian.mods.kubejs.util.Cast; import dev.latvian.mods.kubejs.web.KJSHTTPRequest; +import dev.latvian.mods.kubejs.web.LocalWebServer; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; @@ -61,6 +62,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.nio.file.Files; +import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; @@ -233,7 +235,7 @@ private static HTTPResponse renderAnimated(KJSHTTPRequest req, String dir, @Null req.runInMainThread(() -> { for (var response : responses) { try { - var content = new ContentGrabber(); + var content = new ContentGrabber(LocalWebServer.SERVER_NAME, req.startTime()); response.build(content); if (content.body != null && bodyKeys.add(new BodyKey(content.body))) { @@ -444,9 +446,13 @@ public static HTTPResponse fluidTag(KJSHTTPRequest req) throws Exception { return renderAnimated(req, "fluid_tag", buf, list); } - private static class ContentGrabber extends HTTPResponseBuilder { + private static class ContentGrabber extends HTTPPayload { private byte[] body = null; + public ContentGrabber(String serverName, Instant serverTime) { + super(serverName, serverTime); + } + @Override public void setBody(ResponseContent body) { try {