diff --git a/commafeed-server/src/main/java/com/commafeed/backend/favicon/RootFaviconFetcher.java b/commafeed-server/src/main/java/com/commafeed/backend/favicon/RootFaviconFetcher.java index 4e2e6699..20190a40 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/favicon/RootFaviconFetcher.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/favicon/RootFaviconFetcher.java @@ -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); diff --git a/commafeed-server/src/test/java/com/commafeed/backend/favicon/RootFaviconFetcherTest.java b/commafeed-server/src/test/java/com/commafeed/backend/favicon/RootFaviconFetcherTest.java index 662361e1..6b117050 100644 --- a/commafeed-server/src/test/java/com/commafeed/backend/favicon/RootFaviconFetcherTest.java +++ b/commafeed-server/src/test/java/com/commafeed/backend/favicon/RootFaviconFetcherTest.java @@ -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();