From 55c2c952694920f0c43efdf8ab180c520557de47 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 13 Apr 2024 16:30:22 +0100 Subject: [PATCH] only fetch the head on the endpoint status check --- src/main/java/cc/fascinated/common/WebRequest.java | 14 ++++++++++++++ .../java/cc/fascinated/service/MojangService.java | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/cc/fascinated/common/WebRequest.java b/src/main/java/cc/fascinated/common/WebRequest.java index 76001ad..1746cff 100644 --- a/src/main/java/cc/fascinated/common/WebRequest.java +++ b/src/main/java/cc/fascinated/common/WebRequest.java @@ -60,4 +60,18 @@ public class WebRequest { .onStatus(HttpStatusCode::isError, (request, response) -> {}) // Don't throw exceptions on error .toEntity(clazz); } + + /** + * Gets a response from the given URL. + * + * @param url the url + * @return the response + */ + public static ResponseEntity head(String url, Class clazz) { + return CLIENT.head() + .uri(url) + .retrieve() + .onStatus(HttpStatusCode::isError, (request, response) -> {}) // Don't throw exceptions on error + .toEntity(clazz); + } } diff --git a/src/main/java/cc/fascinated/service/MojangService.java b/src/main/java/cc/fascinated/service/MojangService.java index 1157667..d4f14b3 100644 --- a/src/main/java/cc/fascinated/service/MojangService.java +++ b/src/main/java/cc/fascinated/service/MojangService.java @@ -199,7 +199,7 @@ public class MojangService { for (EndpointStatus endpoint : MOJANG_ENDPOINTS) { CompletableFuture future = CompletableFuture.supplyAsync(() -> { boolean online = false; - ResponseEntity response = WebRequest.get(endpoint.getEndpoint(), String.class); + ResponseEntity response = WebRequest.head(endpoint.getEndpoint(), String.class); if (endpoint.getAllowedStatuses().contains(response.getStatusCode())) { online = true; }