Merge branch 'microsoft:main' into main
commit
5ba02760a2
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue