diff --git a/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/ResponseBuilder.java b/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/ResponseBuilder.java index 3274a8dc0..38a5a7efb 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/ResponseBuilder.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/ResponseBuilder.java @@ -132,6 +132,10 @@ public class ResponseBuilder { */ public Response build() { byte[] content = response.bytes; + if(content == null && response.code == 204) { + // HTTP Code 204 requires no response, so there is no need to validate it. + return response; + } exceptionIf(content == null, "Content not defined for Response"); String mimeType = getMimeType(); exceptionIf(content.length > 0 && mimeType == null, "MIME Type not defined for Response"); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/ResponseResolver.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/ResponseResolver.java index 5dbc4769f..2e5cae17d 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/ResponseResolver.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/ResponseResolver.java @@ -158,7 +158,7 @@ public class ResponseResolver { private Response tryToGetResponse(Request request) { if ("OPTIONS".equalsIgnoreCase(request.getMethod())) { // https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS - return Response.builder().setStatus(204).setContent(new byte[0]).build(); + return Response.builder().setStatus(204).build(); } Optional user = request.getUser(); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/ResponseSender.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/ResponseSender.java index 043f45fe1..8907476db 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/ResponseSender.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/ResponseSender.java @@ -45,7 +45,7 @@ public class ResponseSender { public void send() throws IOException { setResponseHeaders(); - if ("HEAD".equals(exchange.getRequestMethod())) { + if ("HEAD".equals(exchange.getRequestMethod()) || response.getCode() == 204) { sendHeadResponse(); } else if ("bytes".equalsIgnoreCase(response.getHeaders().get("Accept-Ranges"))) { sendRawBytes(); @@ -91,7 +91,9 @@ public class ResponseSender { } private void beginSend() throws IOException { - exchange.sendResponseHeaders(response.getCode(), 0); + // Return a content length of -1 for HTTP code 204 (No content) + // and HEAD requests to avoid warning messages. + exchange.sendResponseHeaders(response.getCode(), (response.getCode() == 204 || "HEAD".equals(exchange.getRequestMethod())) ? -1 : 0); } private void sendRawBytes() throws IOException {