From fc8b959fea3f3c4d4e9b7a19b09601ac74d1ac87 Mon Sep 17 00:00:00 2001 From: Daniele Gobbetti Date: Sat, 8 Jun 2024 16:29:52 +0200 Subject: [PATCH] Garmin: only add the cache-control header when updating the AGPS file Prevents it being stale for too long if the user forgets to fetch an updated file. If the file has to be updated on the watch the response (http status 200) is sent and cached for 14400 seconds, for this period the watch will not request the file again. Subsequent requests (http status 304) are very small and should not impact battery life negatively, hence they are sent without adding caching directives. --- .../gadgetbridge/service/devices/garmin/agps/AgpsHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/agps/AgpsHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/agps/AgpsHandler.java index c3b462611..5ea9a6e5a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/agps/AgpsHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/agps/AgpsHandler.java @@ -50,7 +50,6 @@ public class AgpsHandler { } final GarminHttpResponse response = new GarminHttpResponse(); - response.getHeaders().put("cache-control", "max-age=14400"); final byte[] rawBytes = FileUtils.readAll(agpsIn, 1024 * 1024); // 1MB, they're usually ~60KB final String fileHash = GB.hexdump(CheckSums.md5(rawBytes)).toLowerCase(Locale.ROOT); @@ -68,6 +67,7 @@ public class AgpsHandler { return response; } } + response.getHeaders().put("cache-control", "max-age=14400"); // Run some sanity checks on known agps file formats final GarminAgpsFile garminAgpsFile = new GarminAgpsFile(rawBytes);