using System;
using System.Collections.Generic;
using System.Threading;
using Flurl.Http;
namespace Kavita.Common.Helpers;
///
/// Helper class for configuring Flurl client for a specific URL.
///
public static class FlurlConfiguration
{
private static readonly List ConfiguredClients = new List();
private static readonly Lock Lock = new Lock();
///
/// Configures the Flurl client for the specified URL.
///
/// The URL to configure the client for.
public static void ConfigureClientForUrl(string url)
{
//Important client are mapped without path, per example two urls pointing to the same host:port but different path, will use the same client.
lock (Lock)
{
var ur = new Uri(url);
//key is host:port
var host = ur.Host + ":" + ur.Port;
if (ConfiguredClients.Contains(host)) return;
FlurlHttp.ConfigureClientForUrl(url).ConfigureInnerHandler(cli =>
#pragma warning disable S4830
cli.ServerCertificateCustomValidationCallback = (_, _, _, _) => true);
#pragma warning restore S4830
ConfiguredClients.Add(host);
}
}
}