Merge branch 'microsoft:main' into main

pull/213/head
Soruk 2023-02-11 18:01:02 +01:00 committed by GitHub
commit 5ba02760a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 25 deletions

View File

@ -26,8 +26,7 @@ var queueConnectionString = builder.Configuration.GetConnectionString("FeedQueue
builder.Services.AddSingleton(new QueueClient(queueConnectionString, "feed-queue"));
builder.Services.AddHttpClient<IFeedClient, FeedClient>();
builder.Services.AddTransient<JitterHandler>();
builder.Services.AddHttpClient<ShowClient>().AddHttpMessageHandler<JitterHandler>();
builder.Services.AddHttpClient<ShowClient>();
// Authentication and authorization-related services
// Comment back in if testing authentication

View File

@ -4,32 +4,20 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Podcast.Infrastructure.Http
namespace Podcast.Infrastructure.Http;
public class ShowClient
{
public class JitterHandler : DelegatingHandler
private readonly HttpClient _httpClient;
public ShowClient(HttpClient httpClient)
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
// Who would do such a thing?!
// TODO fix this horrible perf leak!
await Task.Delay(TimeSpan.FromMilliseconds(Random.Shared.NextInt64(50, 500)));
return await base.SendAsync(request, cancellationToken);
}
_httpClient = httpClient;
}
public class ShowClient
public async Task<bool> CheckLink(string showLink)
{
private readonly HttpClient _httpClient;
public ShowClient(HttpClient httpClient)
{
_httpClient = httpClient;
}
public async Task<bool> CheckLink(string showLink)
{
var response = await _httpClient.GetAsync(showLink, HttpCompletionOption.ResponseHeadersRead);
return response.IsSuccessStatusCode;
}
var response = await _httpClient.GetAsync(showLink, HttpCompletionOption.ResponseHeadersRead);
return response.IsSuccessStatusCode;
}
}
}