From a7b65c031d3307ca47653a89564902750d5b723f Mon Sep 17 00:00:00 2001 From: CodingPhoenixx Date: Fri, 29 May 2026 09:00:31 +0200 Subject: [PATCH] Add constructors and Javadoc comments to improve clarity and completeness across server components, including WebSocket and routing classes. --- .../nextusweb/server/cores/CorsConfig.java | 19 +++++++++++++++++ .../server/ratelimit/RateLimitConfig.java | 7 +++++++ .../nextusweb/server/router/Response.java | 9 +++++++- .../coph/nextusweb/server/router/Router.java | 6 ++++++ .../server/websocket/WebSocketConfig.java | 21 +++++++++++++++++++ .../server/websocket/WebSocketGroup.java | 4 ++++ .../server/websocket/WebSocketRouter.java | 6 ++++++ .../server/websocket/WebSocketSession.java | 8 +++++++ 8 files changed, 79 insertions(+), 1 deletion(-) diff --git a/src/main/java/dev/coph/nextusweb/server/cores/CorsConfig.java b/src/main/java/dev/coph/nextusweb/server/cores/CorsConfig.java index 6042c72..fc37463 100644 --- a/src/main/java/dev/coph/nextusweb/server/cores/CorsConfig.java +++ b/src/main/java/dev/coph/nextusweb/server/cores/CorsConfig.java @@ -99,6 +99,8 @@ public final class CorsConfig { } /** + * Returns the HTTP methods advertised as allowed in preflight responses. + * * @return the immutable set of allowed HTTP methods */ public Set allowedMethods() { @@ -106,6 +108,8 @@ public final class CorsConfig { } /** + * Returns the request headers advertised as allowed in preflight responses. + * * @return the immutable set of allowed request headers */ public Set allowedHeaders() { @@ -113,6 +117,8 @@ public final class CorsConfig { } /** + * Returns the response headers that browsers are permitted to read. + * * @return the immutable set of response headers exposed to the browser */ public Set exposedHeaders() { @@ -120,6 +126,8 @@ public final class CorsConfig { } /** + * Indicates whether credentialed (cookie/authorization) requests are permitted. + * * @return {@code true} if credentialed requests are permitted */ public boolean allowCredentials() { @@ -127,6 +135,8 @@ public final class CorsConfig { } /** + * Returns how long a preflight response may be cached by the browser. + * * @return the preflight cache lifetime in seconds ({@code 0} disables the header) */ public long maxAgeSeconds() { @@ -134,6 +144,8 @@ public final class CorsConfig { } /** + * Indicates whether requests from any origin are permitted. + * * @return {@code true} if any origin is permitted */ public boolean allowAnyOrigin() { @@ -160,6 +172,13 @@ public final class CorsConfig { /** Whether any origin is permitted; defaults to {@code false}. */ private boolean allowAnyOrigin = false; + /** + * Creates a builder with no origins, methods or headers configured and all flags at + * their defaults. Obtain instances via {@link CorsConfig#builder()}. + */ + public Builder() { + } + /** * Adds one or more explicit origins to the allow-list. * diff --git a/src/main/java/dev/coph/nextusweb/server/ratelimit/RateLimitConfig.java b/src/main/java/dev/coph/nextusweb/server/ratelimit/RateLimitConfig.java index cc35177..7e3d9cf 100644 --- a/src/main/java/dev/coph/nextusweb/server/ratelimit/RateLimitConfig.java +++ b/src/main/java/dev/coph/nextusweb/server/ratelimit/RateLimitConfig.java @@ -110,6 +110,13 @@ public final class RateLimitConfig { /** The global rule, if configured. */ private Rule globalRule; + /** + * Creates a builder with no rules configured. Obtain instances via + * {@link RateLimitConfig#builder()}. + */ + public Builder() { + } + /** * Sets the global rule applied to every request. * diff --git a/src/main/java/dev/coph/nextusweb/server/router/Response.java b/src/main/java/dev/coph/nextusweb/server/router/Response.java index 2c77809..147f4cb 100644 --- a/src/main/java/dev/coph/nextusweb/server/router/Response.java +++ b/src/main/java/dev/coph/nextusweb/server/router/Response.java @@ -25,6 +25,13 @@ public final class Response { /** Response body bytes; defaults to an empty array. */ private byte[] body = new byte[0]; + /** + * Creates an empty response with status {@code 200}, no headers and an empty body, ready to + * be populated fluently by a handler. + */ + public Response() { + } + /** * Sets the HTTP status code. * @@ -106,7 +113,7 @@ public final class Response { /** * Returns the response body bytes. * - * @return the body + * @return the body bytes */ public byte[] body() { return body; } } diff --git a/src/main/java/dev/coph/nextusweb/server/router/Router.java b/src/main/java/dev/coph/nextusweb/server/router/Router.java index 642054d..364eee9 100644 --- a/src/main/java/dev/coph/nextusweb/server/router/Router.java +++ b/src/main/java/dev/coph/nextusweb/server/router/Router.java @@ -34,6 +34,12 @@ public final class Router { /** Middlewares executed in insertion order for every matched request. */ private final List> middlewares = new ArrayList<>(); + /** + * Creates an empty router with no registered routes and no middlewares. + */ + public Router() { + } + /** * Registers a middleware that runs against every matched request before its handler. * diff --git a/src/main/java/dev/coph/nextusweb/server/websocket/WebSocketConfig.java b/src/main/java/dev/coph/nextusweb/server/websocket/WebSocketConfig.java index d24f39a..ba1c1d8 100644 --- a/src/main/java/dev/coph/nextusweb/server/websocket/WebSocketConfig.java +++ b/src/main/java/dev/coph/nextusweb/server/websocket/WebSocketConfig.java @@ -80,6 +80,8 @@ public final class WebSocketConfig { } /** + * Returns the maximum size of a single WebSocket frame payload. + * * @return the maximum single-frame payload size in bytes */ public int maxFramePayloadLength() { @@ -87,6 +89,8 @@ public final class WebSocketConfig { } /** + * Returns the maximum size of an aggregated (multi-frame) message. + * * @return the maximum aggregated message size in bytes */ public int maxAggregatedMessageSize() { @@ -94,6 +98,8 @@ public final class WebSocketConfig { } /** + * Returns the idle timeout after which inactive connections are closed. + * * @return the idle timeout, or {@code null} if idle connections are never closed */ public Duration idleTimeout() { @@ -101,6 +107,8 @@ public final class WebSocketConfig { } /** + * Indicates whether connections from any origin are accepted. + * * @return {@code true} if connections from any origin are accepted */ public boolean allowAnyOrigin() { @@ -108,6 +116,8 @@ public final class WebSocketConfig { } /** + * Returns the explicitly allowed origins. + * * @return the immutable set of explicitly allowed origins */ public Set allowedOrigins() { @@ -126,6 +136,8 @@ public final class WebSocketConfig { } /** + * Indicates whether per-message deflate compression is enabled. + * * @return {@code true} if per-message compression is enabled */ public boolean compression() { @@ -133,6 +145,8 @@ public final class WebSocketConfig { } /** + * Indicates whether the WebSocket path is matched by prefix rather than exact equality. + * * @return {@code true} if the WebSocket path is matched by prefix rather than exactly */ public boolean checkStartsWith() { @@ -162,6 +176,13 @@ public final class WebSocketConfig { /** Whether path matching uses a prefix check; defaults to {@code false}. */ private boolean checkStartsWith = false; + /** + * Creates a builder pre-populated with the default configuration values described + * above. Obtain instances via {@link WebSocketConfig#builder()}. + */ + public Builder() { + } + /** * Sets the maximum single-frame payload size. * diff --git a/src/main/java/dev/coph/nextusweb/server/websocket/WebSocketGroup.java b/src/main/java/dev/coph/nextusweb/server/websocket/WebSocketGroup.java index 8f0884c..7680a25 100644 --- a/src/main/java/dev/coph/nextusweb/server/websocket/WebSocketGroup.java +++ b/src/main/java/dev/coph/nextusweb/server/websocket/WebSocketGroup.java @@ -42,6 +42,8 @@ public final class WebSocketGroup { } /** + * Returns the name of this group. + * * @return the group name */ public String name() { @@ -71,6 +73,8 @@ public final class WebSocketGroup { } /** + * Returns how many connections are currently in the group. + * * @return the current number of member connections */ public int size() { diff --git a/src/main/java/dev/coph/nextusweb/server/websocket/WebSocketRouter.java b/src/main/java/dev/coph/nextusweb/server/websocket/WebSocketRouter.java index 9692f62..a976547 100644 --- a/src/main/java/dev/coph/nextusweb/server/websocket/WebSocketRouter.java +++ b/src/main/java/dev/coph/nextusweb/server/websocket/WebSocketRouter.java @@ -19,6 +19,12 @@ public final class WebSocketRouter { /** Root of the routing trie. */ private final Node root = new Node(); + /** + * Creates an empty WebSocket router with no registered handlers. + */ + public WebSocketRouter() { + } + /** * Registers a handler at the given path, creating any missing trie nodes. Segments wrapped * in braces (e.g. {@code /chat/{room}}) are treated as path parameters. diff --git a/src/main/java/dev/coph/nextusweb/server/websocket/WebSocketSession.java b/src/main/java/dev/coph/nextusweb/server/websocket/WebSocketSession.java index 7c8aced..1cc6492 100644 --- a/src/main/java/dev/coph/nextusweb/server/websocket/WebSocketSession.java +++ b/src/main/java/dev/coph/nextusweb/server/websocket/WebSocketSession.java @@ -66,6 +66,8 @@ public final class WebSocketSession { } /** + * Returns the unique identifier generated for this session. + * * @return the unique session id */ public String id() { @@ -73,6 +75,8 @@ public final class WebSocketSession { } /** + * Returns the path the connection was established on. + * * @return the path the connection was established on */ public String path() { @@ -90,6 +94,8 @@ public final class WebSocketSession { } /** + * Indicates whether the connection is still open. + * * @return {@code true} if the underlying channel is still active (open) */ public boolean isOpen() { @@ -111,6 +117,8 @@ public final class WebSocketSession { } /** + * Returns the underlying Netty channel for advanced, low-level use. + * * @return the underlying Netty channel, for advanced use */ public Channel channel() {