when validating URLs, use HEAD requests to save bandwidth

This commit is contained in:
Collin M. Barrett 2019-07-03 20:18:59 -05:00
parent 4c5698472f
commit b8bd642fad

View file

@ -71,7 +71,8 @@ private TransformBlock<Uri, UrlValidationResult> BuildValidator(CancellationToke
try
{
var response = await _httpClient.GetAsync(u, cancellationToken);
var response = await _httpClient.GetAsync(u, HttpCompletionOption.ResponseHeadersRead,
cancellationToken);
if (u.Scheme == Uri.UriSchemeHttp && await IsHttpsSupported(u, cancellationToken))
result.SetSupportsHttps();
if (response.IsSuccessStatusCode)
@ -117,7 +118,8 @@ private async Task<bool> IsHttpsSupported(Uri url, CancellationToken cancellatio
var httpsUrl = new UriBuilder(url.OriginalString) {Scheme = Uri.UriSchemeHttps}.Uri;
try
{
var response = await _httpClient.GetAsync(httpsUrl, cancellationToken);
var response = await _httpClient.GetAsync(httpsUrl, HttpCompletionOption.ResponseHeadersRead,
cancellationToken);
if (response.IsSuccessStatusCode)
return true;
_logger.LogError(