1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-04 17:27:24 +01:00

Garmin: Fix 304 response when agps matches cache

This commit is contained in:
José Rebelo 2024-05-23 22:11:34 +01:00 committed by Daniele Gobbetti
parent ba9e5c8a77
commit b704276e49
2 changed files with 5 additions and 4 deletions

View File

@ -50,6 +50,7 @@ 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);
@ -62,9 +63,9 @@ public class AgpsHandler {
LOG.debug("agps request hash = {}, file hash = {}", ifNoneMatch, etag);
if (etag.equals(ifNoneMatch)) {
// FIXME: the 304 reboots some watches, so just ignore the request if the hash matches
//response.setStatus(304);
return null;
response.setBody(new byte[0]);
response.setStatus(304);
return response;
}
}

View File

@ -131,7 +131,7 @@ public class HttpHandler {
}
return GdiHttpService.HttpService.RawResponse.newBuilder()
.setStatus(GdiHttpService.HttpService.Status.OK)
.setStatus(response.getStatus() / 100 == 2 ? GdiHttpService.HttpService.Status.OK : GdiHttpService.HttpService.Status.UNKNOWN_STATUS)
.setHttpStatus(response.getStatus())
.setBody(ByteString.copyFrom(responseBody))
.addAllHeader(responseHeaders)