Skip to content

Commit

Permalink
Generate id for nostore cache if etag is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
cjmalloy committed Apr 10, 2024
1 parent ec1139e commit e6a660a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/jasper/component/WebScraper.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -630,14 +631,15 @@ public Cache fetch(String url, String origin, OutputStream os, boolean refresh)
try (var res = doScrape(url)) {
if (res == null) return existingCache;
var mimeType = res.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue();
var eTag = res.getFirstHeader(HttpHeaders.ETAG).getValue();
var contentLength = res.getEntity().getContentLength();
var cos = (CountingOutputStream) (os != null && contentLength <= 0 ? os = new CountingOutputStream(os) : null);
if (existingCache != null && existingCache.isNoStore()) {
if (os != null) StreamUtils.copy(res.getEntity().getContent(), os);
if (cos != null) contentLength = cos.getByteCount();
EntityUtils.consume(res.getEntity());
return Cache.builder()
.id(res.getFirstHeader(HttpHeaders.ETAG).getValue())
.id(isBlank(eTag) ? "nostore_" + UUID.randomUUID() : eTag)
.mimeType(mimeType)
.contentLength(contentLength <= 0 ? null : contentLength)
.build();
Expand Down

0 comments on commit e6a660a

Please sign in to comment.