Search in sources :

Example 1 with CacheControl

use of com.artipie.asto.cache.CacheControl in project maven-adapter by artipie.

the class CachedProxySlice method checksumControl.

/**
 * Checksum cache control verification.
 * @param header Checksum header
 * @return Cache control with digest
 */
private static CacheControl checksumControl(final Header header) {
    final Matcher matcher = CachedProxySlice.CHECKSUM_PATTERN.matcher(header.getKey());
    final CacheControl res;
    if (matcher.matches()) {
        try {
            res = new DigestVerification(new Digests.FromString(CachedProxySlice.DIGEST_NAMES.get(matcher.group(1).toLowerCase(Locale.US))).get(), Hex.decodeHex(header.getValue().toCharArray()));
        } catch (final DecoderException err) {
            throw new IllegalStateException("Invalid digest hex", err);
        }
    } else {
        res = CacheControl.Standard.ALWAYS;
    }
    return res;
}
Also used : Digests(com.artipie.asto.ext.Digests) DigestVerification(com.artipie.asto.cache.DigestVerification) DecoderException(org.apache.commons.codec.DecoderException) Matcher(java.util.regex.Matcher) CacheControl(com.artipie.asto.cache.CacheControl)

Aggregations

CacheControl (com.artipie.asto.cache.CacheControl)1 DigestVerification (com.artipie.asto.cache.DigestVerification)1 Digests (com.artipie.asto.ext.Digests)1 Matcher (java.util.regex.Matcher)1 DecoderException (org.apache.commons.codec.DecoderException)1