diff --git a/adoptium-api-v3-persistence/src/main/kotlin/net/adoptium/api/v3/dataSources/persitence/mongo/UpdatedInfo.kt b/adoptium-api-v3-persistence/src/main/kotlin/net/adoptium/api/v3/dataSources/persitence/mongo/UpdatedInfo.kt index 0d8d63683..235757e87 100644 --- a/adoptium-api-v3-persistence/src/main/kotlin/net/adoptium/api/v3/dataSources/persitence/mongo/UpdatedInfo.kt +++ b/adoptium-api-v3-persistence/src/main/kotlin/net/adoptium/api/v3/dataSources/persitence/mongo/UpdatedInfo.kt @@ -1,16 +1,16 @@ package net.adoptium.api.v3.dataSources.persitence.mongo -import java.math.BigInteger +import com.fasterxml.jackson.annotation.JsonIgnoreProperties import java.time.ZoneId import java.time.ZonedDateTime import java.time.format.DateTimeFormatter import java.util.* +@JsonIgnoreProperties(ignoreUnknown = true) data class UpdatedInfo( val time: ZonedDateTime, val checksum: String, val hashCode: Int, - val hexChecksum: String? = BigInteger(1, Base64.getDecoder().decode(checksum)).toString(16), val lastModified: Date? = Date.from(time.toInstant()), val lastModifiedFormatted: String? = lastModified ?.toInstant() diff --git a/adoptium-frontend-parent/adoptium-api-v3-frontend/src/main/kotlin/net/adoptium/api/v3/CacheControlService.kt b/adoptium-frontend-parent/adoptium-api-v3-frontend/src/main/kotlin/net/adoptium/api/v3/CacheControlService.kt index 6f473ecc6..b175fcfa8 100644 --- a/adoptium-frontend-parent/adoptium-api-v3-frontend/src/main/kotlin/net/adoptium/api/v3/CacheControlService.kt +++ b/adoptium-frontend-parent/adoptium-api-v3-frontend/src/main/kotlin/net/adoptium/api/v3/CacheControlService.kt @@ -33,8 +33,11 @@ class CacheControlService @Inject constructor(private var apiDataStore: APIDataS private fun calculateEtag(requestContext: ContainerRequestContext): String { val md = MessageDigest.getInstance("SHA1") - if (apiDataStore.getUpdateInfo().hexChecksum != null) { - md.update(HexFormat.of().parseHex(apiDataStore.getUpdateInfo().hexChecksum)) + try { + md.update(Base64.getDecoder().decode(apiDataStore.getUpdateInfo().checksum)) + } catch (e: Exception) { + // Should not happen as the hex checksum should always be a valid Base64 string + md.update(apiDataStore.getUpdateInfo().checksum.toByteArray()) } md.update(requestContext.uriInfo.requestUri.toString().toByteArray()) return BigInteger(1, md.digest()).toString(16) @@ -46,12 +49,12 @@ class CacheControlService @Inject constructor(private var apiDataStore: APIDataS val lastModified = apiDataStore.getUpdateInfo().lastModified - if (lastModified == null || etag == null) { + if (lastModified == null) { return } val builder = - requestContext!! + requestContext .request .evaluatePreconditions(lastModified, EntityTag(etag)) @@ -70,8 +73,7 @@ class CacheControlService @Inject constructor(private var apiDataStore: APIDataS ecc.maxAge = MAX_CACHE_AGE_IN_SEC ecc.sMaxAge = MAX_CACHE_AGE_IN_SEC - if (apiDataStore.getUpdateInfo().hexChecksum == null || - apiDataStore.getUpdateInfo().lastModifiedFormatted == null) { + if (apiDataStore.getUpdateInfo().lastModifiedFormatted == null) { return }