From 46d4a53b119bde7484ff65a4cd98d9659a3e0908 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 19 Apr 2024 20:51:33 +0100 Subject: [PATCH] fix cache control, oops --- .../xyz/mcutils/backend/controller/MojangController.java | 2 +- .../xyz/mcutils/backend/controller/PlayerController.java | 6 +++--- .../xyz/mcutils/backend/controller/ServerController.java | 7 +++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/xyz/mcutils/backend/controller/MojangController.java b/src/main/java/xyz/mcutils/backend/controller/MojangController.java index ab170ab..bdd546f 100644 --- a/src/main/java/xyz/mcutils/backend/controller/MojangController.java +++ b/src/main/java/xyz/mcutils/backend/controller/MojangController.java @@ -28,7 +28,7 @@ public class MojangController { CachedEndpointStatus status = mojangService.getMojangApiStatus(); return ResponseEntity.ok() - .cacheControl(CacheControl.maxAge(1, TimeUnit.MINUTES)) + .cacheControl(CacheControl.maxAge(1, TimeUnit.MINUTES).cachePublic()) .eTag(String.valueOf(status.hashCode())) .body(status); } diff --git a/src/main/java/xyz/mcutils/backend/controller/PlayerController.java b/src/main/java/xyz/mcutils/backend/controller/PlayerController.java index ac891aa..8c2a1ef 100644 --- a/src/main/java/xyz/mcutils/backend/controller/PlayerController.java +++ b/src/main/java/xyz/mcutils/backend/controller/PlayerController.java @@ -34,7 +34,7 @@ public class PlayerController { CachedPlayer player = playerService.getPlayer(id); return ResponseEntity.ok() - .cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS)) + .cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS).cachePublic()) .eTag(String.valueOf(player.hashCode())) .body(player); } @@ -46,7 +46,7 @@ public class PlayerController { CachedPlayerName player = playerService.usernameToUuid(id); return ResponseEntity.ok() - .cacheControl(CacheControl.maxAge(6, TimeUnit.HOURS)) + .cacheControl(CacheControl.maxAge(6, TimeUnit.HOURS).cachePublic()) .eTag(String.valueOf(player.hashCode())) .body(player); } @@ -64,7 +64,7 @@ public class PlayerController { // Return the part image return ResponseEntity.ok() - .cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS)) + .cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS).cachePublic()) .contentType(MediaType.IMAGE_PNG) .header(HttpHeaders.CONTENT_DISPOSITION, dispositionHeader.formatted(player.getUsername())) .eTag(String.valueOf(player.hashCode())) diff --git a/src/main/java/xyz/mcutils/backend/controller/ServerController.java b/src/main/java/xyz/mcutils/backend/controller/ServerController.java index 6fbb264..1818620 100644 --- a/src/main/java/xyz/mcutils/backend/controller/ServerController.java +++ b/src/main/java/xyz/mcutils/backend/controller/ServerController.java @@ -38,7 +38,7 @@ public class ServerController { CachedMinecraftServer server = serverService.getServer(platform, hostname); return ResponseEntity.ok() - .cacheControl(CacheControl.maxAge(5, TimeUnit.MINUTES)) + .cacheControl(CacheControl.maxAge(5, TimeUnit.MINUTES).cachePublic()) .eTag(String.valueOf(server.hashCode())) .body(server); } @@ -49,11 +49,10 @@ public class ServerController { @Parameter(description = "The hostname and port of the server", example = "aetheria.cc") @PathVariable String hostname, @Parameter(description = "Whether to download the image") @RequestParam(required = false, defaultValue = "false") boolean download) { String dispositionHeader = download ? "attachment; filename=%s.png" : "inline; filename=%s.png"; - byte[] favicon = serverService.getServerFavicon(hostname); return ResponseEntity.ok() - .cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS)) + .cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS).cachePublic()) .contentType(MediaType.IMAGE_PNG) .header(HttpHeaders.CONTENT_DISPOSITION, dispositionHeader.formatted(hostname)) .eTag(String.valueOf(Arrays.hashCode(favicon))) @@ -65,7 +64,7 @@ public class ServerController { public ResponseEntity getServerBlockedStatus( @Parameter(description = "The hostname of the server", example = "aetheria.cc") @PathVariable String hostname) { return ResponseEntity.ok() - .cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS)) + .cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS).cachePublic()) .eTag(String.valueOf(hostname.hashCode())) .body(Map.of( "blocked", mojangService.isServerBlocked(hostname)