mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
validate is valid syntax of a URL
This commit is contained in:
parent
747c6be1a9
commit
91a724598b
2 changed files with 18 additions and 0 deletions
|
|
@ -9,5 +9,15 @@ public static string GetExtension(this Uri uri)
|
|||
{
|
||||
return Path.GetExtension(uri.AbsolutePath);
|
||||
}
|
||||
|
||||
public static bool IsValidUrl(this Uri uri)
|
||||
{
|
||||
var uriString = uri.OriginalString;
|
||||
if (!Uri.IsWellFormedUriString(uriString, UriKind.Absolute))
|
||||
return false;
|
||||
if (!Uri.TryCreate(uriString, UriKind.Absolute, out var tmp))
|
||||
return false;
|
||||
return tmp.Scheme == Uri.UriSchemeHttp || tmp.Scheme == Uri.UriSchemeHttps;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks.Dataflow;
|
||||
using FilterLists.Agent.Extensions;
|
||||
using FilterLists.Agent.Features.Urls.Models.ValidationResults;
|
||||
using FilterLists.Agent.Infrastructure.Clients;
|
||||
using MediatR;
|
||||
|
|
@ -60,6 +61,13 @@ private TransformBlock<Uri, UrlValidationResult> BuildValidator(CancellationToke
|
|||
async u =>
|
||||
{
|
||||
var result = new UrlValidationResult(u);
|
||||
if (!u.IsValidUrl())
|
||||
{
|
||||
result.SetBroken();
|
||||
_logger.LogError($"{u.AbsoluteUri}) is not a valid URL.");
|
||||
return result;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var response = await _httpClient.GetAsync(u, cancellationToken);
|
||||
|
|
|
|||
Loading…
Reference in a new issue