1- namespace AngleSharp
2- {
1+ namespace AngleSharp
2+ {
3+ using AngleSharp . Dom ;
4+ using AngleSharp . Io ;
35 using AngleSharp . Io . Network ;
4- using System ;
5- using System . Net . Http ;
6-
6+ using System ;
7+ using System . Linq ;
8+ using System . Net . Http ;
9+
710 /// <summary>
811 /// Additional extensions for improved requesters.
912 /// </summary>
1013 public static class IoConfigurationExtensions
1114 {
15+ /// <summary>
16+ /// Adds capability to start a download when following some link to the
17+ /// configuration.
18+ /// </summary>
19+ /// <param name="configuration">The configuration to extend.</param>
20+ /// <param name="download">
21+ /// The callback to invoke when a download should be started. Returns true
22+ /// to signal an interest in downloading the response, otherwise false.
23+ /// </param>
24+ /// <returns>The configuration.</returns>
25+ public static IConfiguration WithDownload ( this IConfiguration configuration , Func < MimeType , IResponse , Boolean > download )
26+ {
27+ var oldFactory = configuration . Services . OfType < IDocumentFactory > ( ) . FirstOrDefault ( ) ;
28+ var newFactory = new DownloadFactory ( oldFactory , download ) ;
29+ return configuration . WithOnly < IDocumentFactory > ( newFactory ) ;
30+ }
31+
1232 /// <summary>
1333 /// Adds the requesters from the AngleSharp.Io package.
1434 /// </summary>
1535 /// <param name="configuration">The configuration to use.</param>
1636 /// <returns>The new configuration.</returns>
17- public static IConfiguration WithRequesters ( this IConfiguration configuration )
18- {
19- return configuration . WithRequesters ( new HttpClientHandler { UseCookies = false , AllowAutoRedirect = false } ) ;
20- }
37+ public static IConfiguration WithRequesters ( this IConfiguration configuration ) =>
38+ configuration . WithRequesters ( new HttpClientHandler { UseCookies = false , AllowAutoRedirect = false } ) ;
2139
2240 /// <summary>
2341 /// Adds the requesters from the AngleSharp.Io package.
@@ -36,7 +54,7 @@ public static IConfiguration WithRequesters(this IConfiguration configuration, H
3654 new DataRequester ( ) ,
3755 new FtpRequester ( ) ,
3856 new FileRequester ( ) ,
39- new AboutRequester ( )
57+ new AboutRequester ( ) ,
4058 } ) ;
4159 }
4260 }
0 commit comments