cache default (missing) favicon too

This commit is contained in:
Athou
2014-10-26 18:13:09 +01:00
parent fa4bfa729d
commit 358a6029a1
4 changed files with 20 additions and 10 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 238 B

View File

@@ -1,27 +1,40 @@
package com.commafeed.backend.service;
import java.io.IOException;
import java.util.Date;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import lombok.RequiredArgsConstructor;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.IOUtils;
import com.commafeed.backend.dao.FeedDAO;
import com.commafeed.backend.favicon.AbstractFaviconFetcher;
import com.commafeed.backend.feed.FeedUtils;
import com.commafeed.backend.model.Feed;
@RequiredArgsConstructor(onConstructor = @__({ @Inject }))
@Singleton
public class FeedService {
private final FeedDAO feedDAO;
private final Set<AbstractFaviconFetcher> faviconFetchers;
private byte[] defaultFavicon;
@Inject
public FeedService(FeedDAO feedDAO, Set<AbstractFaviconFetcher> faviconFetchers) {
this.feedDAO = feedDAO;
this.faviconFetchers = faviconFetchers;
try {
defaultFavicon = IOUtils.toByteArray(getClass().getResource("/images/default_favicon.ico"));
} catch (IOException e) {
throw new RuntimeException("could not load default favicon", e);
}
}
public synchronized Feed findOrCreate(String url) {
String normalized = FeedUtils.normalizeURL(url);
Feed feed = feedDAO.findByUrl(normalized);
@@ -46,6 +59,9 @@ public class FeedService {
break;
}
}
if (icon == null) {
icon = defaultFavicon;
}
return icon;
}

View File

@@ -324,13 +324,7 @@ public class FeedREST {
Feed feed = subscription.getFeed();
byte[] icon = feedService.fetchFavicon(feed);
ResponseBuilder builder = null;
if (icon == null) {
String baseUrl = FeedUtils.removeTrailingSlash(config.getApplicationSettings().getPublicUrl());
builder = Response.status(Status.MOVED_PERMANENTLY).location(URI.create(baseUrl + "/images/default_favicon.gif"));
} else {
builder = Response.ok(icon, "image/x-icon");
}
ResponseBuilder builder = Response.ok(icon, "image/x-icon");
CacheControl cacheControl = new CacheControl();
cacheControl.setMaxAge(2592000);

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB