2025-01-16 11:31:50 +01:00
|
|
|
|
using Logging;
|
|
|
|
|
|
|
|
|
|
|
|
namespace WebUtils
|
|
|
|
|
|
{
|
|
|
|
|
|
public interface IHttpFactory
|
|
|
|
|
|
{
|
|
|
|
|
|
IHttp CreateHttp(string id, Action<HttpClient> onClientCreated);
|
|
|
|
|
|
IHttp CreateHttp(string id, Action<HttpClient> onClientCreated, IWebCallTimeSet timeSet);
|
|
|
|
|
|
IHttp CreateHttp(string id);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class HttpFactory : IHttpFactory
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly ILog log;
|
|
|
|
|
|
private readonly IWebCallTimeSet defaultTimeSet;
|
2025-04-09 15:25:31 +02:00
|
|
|
|
private readonly Action<HttpClient> factoryOnClientCreated;
|
2025-01-16 11:31:50 +01:00
|
|
|
|
|
|
|
|
|
|
public HttpFactory(ILog log)
|
|
|
|
|
|
: this (log, new DefaultWebCallTimeSet())
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-09 15:25:31 +02:00
|
|
|
|
public HttpFactory(ILog log, Action<HttpClient> onClientCreated)
|
|
|
|
|
|
: this(log, new DefaultWebCallTimeSet(), onClientCreated)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-16 11:31:50 +01:00
|
|
|
|
public HttpFactory(ILog log, IWebCallTimeSet defaultTimeSet)
|
2025-04-09 15:25:31 +02:00
|
|
|
|
: this(log, defaultTimeSet, DoNothing)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public HttpFactory(ILog log, IWebCallTimeSet defaultTimeSet, Action<HttpClient> onClientCreated)
|
2025-01-16 11:31:50 +01:00
|
|
|
|
{
|
|
|
|
|
|
this.log = log;
|
|
|
|
|
|
this.defaultTimeSet = defaultTimeSet;
|
2025-04-09 15:25:31 +02:00
|
|
|
|
this.factoryOnClientCreated = onClientCreated;
|
2025-01-16 11:31:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IHttp CreateHttp(string id, Action<HttpClient> onClientCreated)
|
|
|
|
|
|
{
|
|
|
|
|
|
return CreateHttp(id, onClientCreated, defaultTimeSet);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IHttp CreateHttp(string id, Action<HttpClient> onClientCreated, IWebCallTimeSet ts)
|
|
|
|
|
|
{
|
2025-04-09 15:25:31 +02:00
|
|
|
|
return new Http(id, log, ts, (c) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
factoryOnClientCreated(c);
|
|
|
|
|
|
onClientCreated(c);
|
|
|
|
|
|
});
|
2025-01-16 11:31:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IHttp CreateHttp(string id)
|
|
|
|
|
|
{
|
2025-04-09 15:25:31 +02:00
|
|
|
|
return new Http(id, log, defaultTimeSet, factoryOnClientCreated);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void DoNothing(HttpClient client)
|
|
|
|
|
|
{
|
2025-01-16 11:31:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|