diff options
author | Aaron <51387595+AzureAaron@users.noreply.github.com> | 2024-02-19 14:42:58 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-19 14:42:58 -0500 |
commit | 20117e764d3a4f444efd06c846449395caac20aa (patch) | |
tree | 17cbe2e056765d7e9ba138f3c5c37d5f075cba04 /src/main/java | |
parent | 6c3dd6b662ec86b8b7a185de9778ee97d435f3d1 (diff) | |
download | Skyblocker-20117e764d3a4f444efd06c846449395caac20aa.tar.gz Skyblocker-20117e764d3a4f444efd06c846449395caac20aa.tar.bz2 Skyblocker-20117e764d3a4f444efd06c846449395caac20aa.zip |
Support the local memory cache for the API (#558)
Diffstat (limited to 'src/main/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 |