11using System . Net ;
2+ using Humanizer ;
3+ using Lanceur . Core . Configuration ;
4+ using Lanceur . Core . Configuration . Sections ;
25using Lanceur . Core . Services ;
36using Lanceur . SharedKernel . Extensions ;
47using Microsoft . Extensions . Caching . Memory ;
58using Microsoft . Extensions . Logging ;
69
710namespace Lanceur . Infra . Services ;
811
12+ /// <summary>
13+ /// Downloads and caches favicons for a given URL by querying multiple favicon providers
14+ /// (e.g. DuckDuckGo, Google) and falling back to manual file discovery.
15+ /// Failed attempts are recorded in a memory cache to avoid redundant retries
16+ /// until the configured retry delay has elapsed.
17+ /// </summary>
918public class FavIconDownloader : IFavIconDownloader
1019{
1120 #region Fields
1221
13- private readonly HttpClient _client ;
1422 private readonly IMemoryCache _faviconCache ;
1523 private readonly ILogger < FavIconDownloader > _logger ;
1624 private readonly TimeSpan _retryDelay ;
@@ -23,21 +31,23 @@ public class FavIconDownloader : IFavIconDownloader
2331 [ "Manual (ico)" ] = ( IsManual : true , Url : "favicon.ico" )
2432 } ;
2533
34+ private readonly IFavIconHttpClient _httpClient ;
35+
2636 #endregion
2737
2838 #region Constructors
2939
3040 public FavIconDownloader (
3141 ILogger < FavIconDownloader > logger ,
3242 IMemoryCache faviconCache ,
33- TimeSpan retryDelay ,
34- IHttpClientFactory httpClientFactory
43+ ISection < CachingSection > settings ,
44+ IFavIconHttpClient httpClient
3545 )
3646 {
3747 _logger = logger ;
3848 _faviconCache = faviconCache ;
39- _retryDelay = retryDelay ;
40- _client = httpClientFactory . CreateClient ( "favicon" ) ;
49+ _httpClient = httpClient ;
50+ _retryDelay = settings . Value . ThumbnailCacheDuration . Minutes ( ) ;
4151 }
4252
4353 #endregion
@@ -92,7 +102,7 @@ public async Task<bool> RetrieveAndSaveFavicon(Uri url, string outputPath)
92102 try
93103 {
94104 var requestUrl = GetFaviconUrl ( url , faviconUrl ) ;
95- var response = await _client . SendAsync ( new HttpRequestMessage ( HttpMethod . Get , requestUrl ) ) ;
105+ using var response = await _httpClient . SendAsync ( new HttpRequestMessage ( HttpMethod . Get , requestUrl ) ) ;
96106
97107 _logger . LogTrace (
98108 "Checking favicon with {FavIconManager} - Status: {Status} - Host: {Host}" ,
0 commit comments