HTTPCLIENT-2277, regression: corrected wrong variant entry keys in cache hits returned by `BasicHttpCache#getVariants`

This commit is contained in:
Oleg Kalnichevski 2023-09-11 14:01:09 +02:00
parent 889a6bb085
commit 02f09c03f4
2 changed files with 7 additions and 4 deletions

View File

@ -179,9 +179,10 @@ class BasicHttpCache implements HttpCache {
if (root != null && root.hasVariants()) {
final List<CacheHit> variants = new ArrayList<>();
for (final String variantKey : root.getVariants()) {
final HttpCacheEntry variant = getInternal(variantKey + rootKey);
final String variantCacheKey = variantKey + rootKey;
final HttpCacheEntry variant = getInternal(variantCacheKey);
if (variant != null) {
variants.add(new CacheHit(hit.rootKey, variantKey, variant));
variants.add(new CacheHit(rootKey, variantCacheKey, variant));
}
}
return variants;

View File

@ -261,8 +261,10 @@ public class TestBasicHttpCache {
assertNotNull(variantMap);
assertEquals(2, variantMap.size());
MatcherAssert.assertThat(variantMap.get("{accept-encoding=gzip}"), HttpCacheEntryMatcher.equivalent(hit1.entry));
MatcherAssert.assertThat(variantMap.get("{accept-encoding=identity}"), HttpCacheEntryMatcher.equivalent(hit2.entry));
MatcherAssert.assertThat(variantMap.get("{accept-encoding=gzip}" + rootKey),
HttpCacheEntryMatcher.equivalent(hit1.entry));
MatcherAssert.assertThat(variantMap.get("{accept-encoding=identity}" + rootKey),
HttpCacheEntryMatcher.equivalent(hit2.entry));
}
@Test