mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
add initial support for checking if https is valid for a currently http url
This commit is contained in:
parent
4bf7af90ba
commit
d936a49621
1 changed files with 23 additions and 3 deletions
|
|
@ -60,12 +60,14 @@ private TransformBlock<Uri, UrlValidationResult> BuildValidator(CancellationToke
|
|||
try
|
||||
{
|
||||
var response = await _httpClient.GetAsync(u, cancellationToken);
|
||||
if (response.IsSuccessStatusCode)
|
||||
return result;
|
||||
if (response.StatusCode == HttpStatusCode.PermanentRedirect ||
|
||||
response.StatusCode == HttpStatusCode.TemporaryRedirect)
|
||||
result.SetRedirectsTo(response.Headers.Location);
|
||||
//TODO: result.SetSupportsHttps();
|
||||
if (u.Scheme == Uri.UriSchemeHttp && await IsHttpsSupported(u, cancellationToken))
|
||||
result.SetSupportsHttps();
|
||||
if (response.IsSuccessStatusCode)
|
||||
return result;
|
||||
result.SetBroken();
|
||||
return result;
|
||||
}
|
||||
catch (HttpRequestException)
|
||||
|
|
@ -82,6 +84,24 @@ private TransformBlock<Uri, UrlValidationResult> BuildValidator(CancellationToke
|
|||
new ExecutionDataflowBlockOptions {MaxDegreeOfParallelism = MaxDegreeOfParallelism}
|
||||
);
|
||||
}
|
||||
|
||||
private async Task<bool> IsHttpsSupported(Uri url, CancellationToken cancellationToken)
|
||||
{
|
||||
var httpsUrl = new UriBuilder(url.OriginalString) {Scheme = Uri.UriSchemeHttps}.Uri;
|
||||
try
|
||||
{
|
||||
var response = await _httpClient.GetAsync(httpsUrl, cancellationToken);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
catch (HttpRequestException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue