File tree 4 files changed +20
-5
lines changed
adoptium-frontend-parent/adoptium-api-v3-frontend/src
main/kotlin/net/adoptium/api/v3
test/kotlin/net/adoptium/api
adoptium-updater-parent/adoptium-api-v3-updater/src
main/kotlin/net/adoptium/api/v3
test/kotlin/net/adoptium/api
4 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ import net.adoptium.api.v3.dataSources.APIDataStore
11
11
import org.jboss.resteasy.reactive.common.headers.CacheControlDelegate
12
12
import org.jboss.resteasy.reactive.common.util.ExtendedCacheControl
13
13
import org.jboss.resteasy.reactive.server.ServerResponseFilter
14
+ import java.math.BigInteger
15
+ import java.security.MessageDigest
16
+ import java.util.*
14
17
15
18
16
19
@Provider
@@ -28,9 +31,19 @@ class CacheControlService @Inject constructor(private var apiDataStore: APIDataS
28
31
return CACHE_CONTROLLED_PATHS .any { path.startsWith(it) }
29
32
}
30
33
34
+ private fun calculateEtag (requestContext : ContainerRequestContext ): String {
35
+ val md = MessageDigest .getInstance(" SHA1" )
36
+ if (apiDataStore.getUpdateInfo().hexChecksum != null ) {
37
+ md.update(HexFormat .of().parseHex(apiDataStore.getUpdateInfo().hexChecksum))
38
+ }
39
+ md.update(requestContext.uriInfo.requestUri.toString().toByteArray())
40
+ return BigInteger (1 , md.digest()).toString(16 )
41
+ }
42
+
31
43
override fun filter (requestContext : ContainerRequestContext ? ) {
32
44
if (isCacheControlledPath(requestContext)) {
33
- val etag = apiDataStore.getUpdateInfo().hexChecksum
45
+ val etag = calculateEtag(requestContext!! )
46
+
34
47
val lastModified = apiDataStore.getUpdateInfo().lastModified
35
48
36
49
if (lastModified == null || etag == null ) {
Original file line number Diff line number Diff line change @@ -258,7 +258,7 @@ class AssetsResourceFeatureReleasePathTest : AssetsPathTest() {
258
258
fun `if none match applied` () {
259
259
RestAssured .given()
260
260
.`when `()
261
- .header(" If-None-Match" , " d76df8e7aefcf7 " )
261
+ .header(" If-None-Match" , " 808bc9e876e1dd5e15b8eb3377618e1c1b313a1e " )
262
262
.get(" /v3/assets/feature_releases/8/ga" )
263
263
.then()
264
264
.statusCode(304 )
@@ -268,7 +268,7 @@ class AssetsResourceFeatureReleasePathTest : AssetsPathTest() {
268
268
fun `etag applied match applied` () {
269
269
RestAssured .given()
270
270
.`when `()
271
- .header(" If-Match" , " d76df8e7aefcf7 " )
271
+ .header(" If-Match" , " 808bc9e876e1dd5e15b8eb3377618e1c1b313a1e " )
272
272
.get(" /v3/assets/feature_releases/8/ga" )
273
273
.then()
274
274
.statusCode(200 )
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ class V3Updater @Inject constructor(
55
55
private val LOGGER = LoggerFactory .getLogger(this ::class .java)
56
56
57
57
fun calculateChecksum (repo : AdoptRepos ): String {
58
- val md = MessageDigest .getInstance(" MD5 " )
58
+ val md = MessageDigest .getInstance(" SHA256 " )
59
59
val outputStream = object : OutputStream () {
60
60
override fun write (b : Int ) {
61
61
md.update(b.toByte())
@@ -269,6 +269,8 @@ class V3Updater @Inject constructor(
269
269
LOGGER .info(" Updating Release Notes" )
270
270
adoptReleaseNotes.updateReleaseNotes(repo)
271
271
272
+ printRepoDebugInfo(currentRepo, repo, repo)
273
+
272
274
LOGGER .info(" Full update done" )
273
275
return @runBlocking repo
274
276
}
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ class V3UpdaterTest {
25
25
fun `checksum works` () {
26
26
runBlocking {
27
27
val checksum = V3Updater .calculateChecksum(BaseTest .adoptRepos)
28
- assertTrue(checksum.length == 24 )
28
+ assertTrue(checksum.length == 44 )
29
29
}
30
30
}
31
31
You can’t perform that action at this time.
0 commit comments