mirror of
https://github.com/Athou/commafeed.git
synced 2026-09-20 19:51:09 +00:00
correctly handle root favicons for non-default ports
This commit is contained in:
@@ -30,7 +30,12 @@ public class RootFaviconFetcher implements FaviconFetcher {
|
||||
|
||||
try {
|
||||
URI uri = URI.create(url.trim());
|
||||
String faviconUrl = "%s://%s/favicon.ico".formatted(uri.getScheme(), uri.getHost());
|
||||
String faviconUrl =
|
||||
"%s://%s%s/favicon.ico"
|
||||
.formatted(
|
||||
uri.getScheme(),
|
||||
uri.getHost(),
|
||||
uri.getPort() > 0 ? ":" + uri.getPort() : "");
|
||||
|
||||
log.debug("getting root icon at {}", faviconUrl);
|
||||
HttpResult result = getter.get(faviconUrl);
|
||||
|
||||
@@ -47,6 +47,26 @@ class RootFaviconFetcherTest {
|
||||
Assertions.assertTrue(result.mediaType().isCompatible(MediaType.valueOf(contentType)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFetchUsesLinkWhenAvailableWithNonDefaultPort() throws Exception {
|
||||
Feed feed = new Feed();
|
||||
feed.setUrl("https://feeds.example.com:8000/feed");
|
||||
feed.setLink("https://www.example.com:8000/blog");
|
||||
|
||||
byte[] iconBytes = new byte[1000];
|
||||
String contentType = "image/x-icon";
|
||||
HttpResult httpResult =
|
||||
new HttpResult(iconBytes, contentType, null, null, null, Duration.ZERO);
|
||||
Mockito.when(httpGetter.get("https://www.example.com:8000/favicon.ico"))
|
||||
.thenReturn(httpResult);
|
||||
|
||||
Favicon result = faviconFetcher.fetch(feed);
|
||||
|
||||
Assertions.assertNotNull(result);
|
||||
Assertions.assertEquals(iconBytes, result.icon());
|
||||
Assertions.assertTrue(result.mediaType().isCompatible(MediaType.valueOf(contentType)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFetchFallsBackToUrlWhenLinkIsNull() throws Exception {
|
||||
Feed feed = new Feed();
|
||||
|
||||
Reference in New Issue
Block a user