diff options
author | olim <bobq4582@gmail.com> | 2024-02-20 12:11:17 +0000 |
---|---|---|
committer | olim <bobq4582@gmail.com> | 2024-02-20 12:11:17 +0000 |
commit | 9a3deba1170b8ba4c5fdccc0a6df0788123ce041 (patch) | |
tree | d19d7cf6e87def4c9c724c5ca1ce672c40b782ea /src/main/java/de/hysky/skyblocker/utils/Http.java | |
parent | 28299e61238d90d690541e713e1c059e6ec00ed0 (diff) | |
parent | 20117e764d3a4f444efd06c846449395caac20aa (diff) | |
download | Skyblocker-9a3deba1170b8ba4c5fdccc0a6df0788123ce041.tar.gz Skyblocker-9a3deba1170b8ba4c5fdccc0a6df0788123ce041.tar.bz2 Skyblocker-9a3deba1170b8ba4c5fdccc0a6df0788123ce041.zip |
Merge remote-tracking branch 'upstream/master' into chat-rules
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/utils/Http.java')
-rw-r--r-- | src/main/java/de/hysky/skyblocker/utils/Http.java | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/main/java/de/hysky/skyblocker/utils/Http.java b/src/main/java/de/hysky/skyblocker/utils/Http.java index 17079d15..58deced2 100644 --- a/src/main/java/de/hysky/skyblocker/utils/Http.java +++ b/src/main/java/de/hysky/skyblocker/utils/Http.java @@ -53,7 +53,7 @@ public class Http { String body = new String(decodedInputStream.readAllBytes()); HttpHeaders headers = response.headers(); - return new ApiResponse(body, response.statusCode(), getCacheStatus(headers), getAge(headers)); + return new ApiResponse(body, response.statusCode(), getCacheStatuses(headers), getAge(headers)); } public static HttpHeaders sendHeadRequest(String url) throws IOException, InterruptedException { @@ -115,12 +115,12 @@ public class Http { } /** - * Returns the cache status of the resource + * Returns the cache statuses of the resource. All possible cache status values conform to Cloudflare's. * - * @see <a href="https://developers.cloudflare.com/cache/concepts/default-cache-behavior/#cloudflare-cache-responses">Cloudflare Cache Docs</a> + * @see <a href="https://developers.cloudflare.com/cache/concepts/cache-responses/">Cloudflare Cache Docs</a> */ - private static String getCacheStatus(HttpHeaders headers) { - return headers.firstValue("CF-Cache-Status").orElse("UNKNOWN"); + private static String[] getCacheStatuses(HttpHeaders headers) { + return new String[] { headers.firstValue("CF-Cache-Status").orElse("UNKNOWN"), headers.firstValue("Local-Cache-Status").orElse("UNKNOWN") }; } private static int getAge(HttpHeaders headers) { @@ -128,7 +128,7 @@ public class Http { } //TODO If ever needed, we could just replace cache status with the response headers and go from there - public record ApiResponse(String content, int statusCode, String cacheStatus, int age) implements AutoCloseable { + public record ApiResponse(String content, int statusCode, String[] cacheStatuses, int age) implements AutoCloseable { public boolean ok() { return statusCode == 200; @@ -139,7 +139,7 @@ public class Http { } public boolean cached() { - return cacheStatus.equals("HIT"); + return cacheStatuses[0].equals("HIT") || cacheStatuses[1].equals("HIT"); } @Override |