Skip to content

Commit

Permalink
optimize rule providers
Browse files Browse the repository at this point in the history
  • Loading branch information
tinohager committed Feb 12, 2024
1 parent 70400bd commit ac92867
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public LocalFileRuleProvider(string filePath)
}

///<inheritdoc/>
public async Task<IEnumerable<TldRule>> BuildAsync(CancellationToken cancellationToken = default)
public async Task<IEnumerable<TldRule>> BuildAsync(
CancellationToken cancellationToken = default)
{
var ruleData = await this.LoadFromFile().ConfigureAwait(false);

Expand Down
26 changes: 18 additions & 8 deletions src/Nager.PublicSuffix/RuleProviders/WebRuleProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Nager.PublicSuffix.CacheProviders;
using Microsoft.Extensions.Configuration;

Check failure on line 1 in src/Nager.PublicSuffix/RuleProviders/WebRuleProvider.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Extensions' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

Check failure on line 1 in src/Nager.PublicSuffix/RuleProviders/WebRuleProvider.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Extensions' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

Check failure on line 1 in src/Nager.PublicSuffix/RuleProviders/WebRuleProvider.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Extensions' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

Check failure on line 1 in src/Nager.PublicSuffix/RuleProviders/WebRuleProvider.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Extensions' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

Check failure on line 1 in src/Nager.PublicSuffix/RuleProviders/WebRuleProvider.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Extensions' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
using Nager.PublicSuffix.CacheProviders;
using Nager.PublicSuffix.Exceptions;
using Nager.PublicSuffix.Models;
using Nager.PublicSuffix.RuleParsers;
Expand All @@ -14,7 +15,7 @@ namespace Nager.PublicSuffix.RuleProviders
/// </summary>
public class WebRuleProvider : IRuleProvider
{
private readonly string _fileUrl;
private readonly string _dataFileUrl;
private readonly ICacheProvider _cacheProvider;
private readonly HttpClient _httpClient;

Expand All @@ -25,18 +26,26 @@ public class WebRuleProvider : IRuleProvider

/// <summary>
/// WebRuleProvider<br/>
/// Loads the public suffix definition file from a given url
/// Loads the public suffix definition file from the official website
/// </summary>
/// <remarks>It is possible to overwrite the url via configuration parameters <c>Nager:PublicSuffix:DataUrl</c></remarks>
/// <param name="configuration"></param>
/// <param name="httpClient"></param>
/// <param name="url"></param>
/// <param name="cacheProvider">default is <see cref="FileCacheProvider"/></param>
public WebRuleProvider(
IConfiguration configuration,

Check failure on line 36 in src/Nager.PublicSuffix/RuleProviders/WebRuleProvider.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IConfiguration' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 36 in src/Nager.PublicSuffix/RuleProviders/WebRuleProvider.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IConfiguration' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 36 in src/Nager.PublicSuffix/RuleProviders/WebRuleProvider.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IConfiguration' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 36 in src/Nager.PublicSuffix/RuleProviders/WebRuleProvider.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IConfiguration' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 36 in src/Nager.PublicSuffix/RuleProviders/WebRuleProvider.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IConfiguration' could not be found (are you missing a using directive or an assembly reference?)
HttpClient httpClient,
string url = "https://publicsuffix.org/list/public_suffix_list.dat",
ICacheProvider cacheProvider = null)
{
this._httpClient = httpClient;
this._fileUrl = url;

var url = configuration["Nager:PublicSuffix:DataUrl"];
if (string.IsNullOrEmpty(url))
{
url = "https://publicsuffix.org/list/public_suffix_list.dat";
}

this._dataFileUrl = url;

if (cacheProvider == null)
{
Expand All @@ -48,7 +57,8 @@ public WebRuleProvider(
}

///<inheritdoc/>
public async Task<IEnumerable<TldRule>> BuildAsync(CancellationToken cancellationToken = default)
public async Task<IEnumerable<TldRule>> BuildAsync(
CancellationToken cancellationToken = default)
{
var ruleParser = new TldRuleParser();

Expand All @@ -59,7 +69,7 @@ public async Task<IEnumerable<TldRule>> BuildAsync(CancellationToken cancellatio
}
else
{
ruleData = await this.LoadFromUrlAsync(this._fileUrl, cancellationToken).ConfigureAwait(false);
ruleData = await this.LoadFromUrlAsync(this._dataFileUrl, cancellationToken).ConfigureAwait(false);
await this._cacheProvider.SetAsync(ruleData).ConfigureAwait(false);
}

Expand Down

0 comments on commit ac92867

Please sign in to comment.