Hash path-based metadata cache keys
Conan, CRAN, Conda, RPM, the main Debian archive and the default Maven
repository keyed cached metadata by the request path with '/' replaced
by '_'. Names and versions may contain '_', so foo/bar_1.0 and
foo_bar/1.0 shared an entry, and with cache_metadata one reference's
recipe files were served for the other. Conan also appended the query
with '_', so a path without a query could collide with a shorter path
plus one.
Hash the upstream URL, the path and, for Conan, the query instead, as
the APK, Arch, generic and Helm handlers already do. Each part is
length-prefixed so no two inputs share a key.
2026-10-24 08:02:07 +02:00
|
|
|
package handler
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"crypto/sha256"
|
|
|
|
|
"encoding/hex"
|
|
|
|
|
"strconv"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// hashedCacheKey derives a metadata cache key from parts such as the
|
|
|
|
|
// upstream URL, the request path and the query. Each part is length-prefixed
|
|
|
|
|
// before hashing, so no two different part lists share a key, whatever bytes
|
2026-10-25 09:55:14 +00:00
|
|
|
// the parts contain.
|
Hash path-based metadata cache keys
Conan, CRAN, Conda, RPM, the main Debian archive and the default Maven
repository keyed cached metadata by the request path with '/' replaced
by '_'. Names and versions may contain '_', so foo/bar_1.0 and
foo_bar/1.0 shared an entry, and with cache_metadata one reference's
recipe files were served for the other. Conan also appended the query
with '_', so a path without a query could collide with a shorter path
plus one.
Hash the upstream URL, the path and, for Conan, the query instead, as
the APK, Arch, generic and Helm handlers already do. Each part is
length-prefixed so no two inputs share a key.
2026-10-24 08:02:07 +02:00
|
|
|
func hashedCacheKey(parts ...string) string {
|
|
|
|
|
h := sha256.New()
|
|
|
|
|
for _, part := range parts {
|
|
|
|
|
_, _ = h.Write([]byte(strconv.Itoa(len(part))))
|
|
|
|
|
_, _ = h.Write([]byte{':'})
|
|
|
|
|
_, _ = h.Write([]byte(part))
|
|
|
|
|
}
|
|
|
|
|
return hex.EncodeToString(h.Sum(nil))
|
|
|
|
|
}
|