fix cache control, oops
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m47s

This commit is contained in:
Lee 2024-04-19 20:51:33 +01:00
parent d0cfd03ad9
commit 46d4a53b11
3 changed files with 7 additions and 8 deletions

@ -28,7 +28,7 @@ public class MojangController {
CachedEndpointStatus status = mojangService.getMojangApiStatus(); CachedEndpointStatus status = mojangService.getMojangApiStatus();
return ResponseEntity.ok() return ResponseEntity.ok()
.cacheControl(CacheControl.maxAge(1, TimeUnit.MINUTES)) .cacheControl(CacheControl.maxAge(1, TimeUnit.MINUTES).cachePublic())
.eTag(String.valueOf(status.hashCode())) .eTag(String.valueOf(status.hashCode()))
.body(status); .body(status);
} }

@ -34,7 +34,7 @@ public class PlayerController {
CachedPlayer player = playerService.getPlayer(id); CachedPlayer player = playerService.getPlayer(id);
return ResponseEntity.ok() return ResponseEntity.ok()
.cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS)) .cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS).cachePublic())
.eTag(String.valueOf(player.hashCode())) .eTag(String.valueOf(player.hashCode()))
.body(player); .body(player);
} }
@ -46,7 +46,7 @@ public class PlayerController {
CachedPlayerName player = playerService.usernameToUuid(id); CachedPlayerName player = playerService.usernameToUuid(id);
return ResponseEntity.ok() return ResponseEntity.ok()
.cacheControl(CacheControl.maxAge(6, TimeUnit.HOURS)) .cacheControl(CacheControl.maxAge(6, TimeUnit.HOURS).cachePublic())
.eTag(String.valueOf(player.hashCode())) .eTag(String.valueOf(player.hashCode()))
.body(player); .body(player);
} }
@ -64,7 +64,7 @@ public class PlayerController {
// Return the part image // Return the part image
return ResponseEntity.ok() return ResponseEntity.ok()
.cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS)) .cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS).cachePublic())
.contentType(MediaType.IMAGE_PNG) .contentType(MediaType.IMAGE_PNG)
.header(HttpHeaders.CONTENT_DISPOSITION, dispositionHeader.formatted(player.getUsername())) .header(HttpHeaders.CONTENT_DISPOSITION, dispositionHeader.formatted(player.getUsername()))
.eTag(String.valueOf(player.hashCode())) .eTag(String.valueOf(player.hashCode()))

@ -38,7 +38,7 @@ public class ServerController {
CachedMinecraftServer server = serverService.getServer(platform, hostname); CachedMinecraftServer server = serverService.getServer(platform, hostname);
return ResponseEntity.ok() return ResponseEntity.ok()
.cacheControl(CacheControl.maxAge(5, TimeUnit.MINUTES)) .cacheControl(CacheControl.maxAge(5, TimeUnit.MINUTES).cachePublic())
.eTag(String.valueOf(server.hashCode())) .eTag(String.valueOf(server.hashCode()))
.body(server); .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 = "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) { @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"; String dispositionHeader = download ? "attachment; filename=%s.png" : "inline; filename=%s.png";
byte[] favicon = serverService.getServerFavicon(hostname); byte[] favicon = serverService.getServerFavicon(hostname);
return ResponseEntity.ok() return ResponseEntity.ok()
.cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS)) .cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS).cachePublic())
.contentType(MediaType.IMAGE_PNG) .contentType(MediaType.IMAGE_PNG)
.header(HttpHeaders.CONTENT_DISPOSITION, dispositionHeader.formatted(hostname)) .header(HttpHeaders.CONTENT_DISPOSITION, dispositionHeader.formatted(hostname))
.eTag(String.valueOf(Arrays.hashCode(favicon))) .eTag(String.valueOf(Arrays.hashCode(favicon)))
@ -65,7 +64,7 @@ public class ServerController {
public ResponseEntity<?> getServerBlockedStatus( public ResponseEntity<?> getServerBlockedStatus(
@Parameter(description = "The hostname of the server", example = "aetheria.cc") @PathVariable String hostname) { @Parameter(description = "The hostname of the server", example = "aetheria.cc") @PathVariable String hostname) {
return ResponseEntity.ok() return ResponseEntity.ok()
.cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS)) .cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS).cachePublic())
.eTag(String.valueOf(hostname.hashCode())) .eTag(String.valueOf(hostname.hashCode()))
.body(Map.of( .body(Map.of(
"blocked", mojangService.isServerBlocked(hostname) "blocked", mojangService.isServerBlocked(hostname)