mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2026-01-06 16:53:59 +00:00
Failover: using HttpClientNetworkHandler that does retries as well as resolves via given dns client.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Technitium DNS Server
|
||||
Copyright (C) 2022 Shreyas Zare (shreyas@technitium.com)
|
||||
Copyright (C) 2023 Shreyas Zare (shreyas@technitium.com)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -29,6 +29,7 @@ using TechnitiumLibrary;
|
||||
using TechnitiumLibrary.Net;
|
||||
using TechnitiumLibrary.Net.Dns;
|
||||
using TechnitiumLibrary.Net.Dns.ResourceRecords;
|
||||
using TechnitiumLibrary.Net.Http.Client;
|
||||
using TechnitiumLibrary.Net.Proxy;
|
||||
|
||||
namespace Failover
|
||||
@@ -61,6 +62,7 @@ namespace Failover
|
||||
WebHook _webHook;
|
||||
|
||||
SocketsHttpHandler _httpHandler;
|
||||
HttpClientNetworkHandler _httpCustomResolverHandler;
|
||||
HttpClient _httpClient;
|
||||
|
||||
#endregion
|
||||
@@ -157,9 +159,12 @@ namespace Failover
|
||||
}
|
||||
}
|
||||
|
||||
if ((_httpCustomResolverHandler is null) || handlerChanged)
|
||||
_httpCustomResolverHandler = new HttpClientNetworkHandler(_httpHandler, _service.DnsServer.PreferIPv6 ? HttpClientNetworkType.PreferIPv6 : HttpClientNetworkType.Default, _service.DnsServer);
|
||||
|
||||
if (_httpClient is null)
|
||||
{
|
||||
HttpClient httpClient = new HttpClient(_httpHandler);
|
||||
HttpClient httpClient = new HttpClient(_httpCustomResolverHandler);
|
||||
httpClient.Timeout = TimeSpan.FromMilliseconds(_timeout);
|
||||
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(HTTP_HEALTH_CHECK_USER_AGENT);
|
||||
httpClient.DefaultRequestHeaders.ConnectionClose = true;
|
||||
@@ -170,7 +175,7 @@ namespace Failover
|
||||
{
|
||||
if (handlerChanged || (_httpClient.Timeout.TotalMilliseconds != _timeout))
|
||||
{
|
||||
HttpClient httpClient = new HttpClient(_httpHandler);
|
||||
HttpClient httpClient = new HttpClient(_httpCustomResolverHandler);
|
||||
httpClient.Timeout = TimeSpan.FromMilliseconds(_timeout);
|
||||
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(HTTP_HEALTH_CHECK_USER_AGENT);
|
||||
httpClient.DefaultRequestHeaders.ConnectionClose = true;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Technitium DNS Server
|
||||
Copyright (C) 2022 Shreyas Zare (shreyas@technitium.com)
|
||||
Copyright (C) 2023 Shreyas Zare (shreyas@technitium.com)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -27,6 +27,7 @@ using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using TechnitiumLibrary;
|
||||
using TechnitiumLibrary.Net.Dns.ResourceRecords;
|
||||
using TechnitiumLibrary.Net.Http.Client;
|
||||
using TechnitiumLibrary.Net.Proxy;
|
||||
|
||||
namespace Failover
|
||||
@@ -42,6 +43,7 @@ namespace Failover
|
||||
Uri[] _urls;
|
||||
|
||||
SocketsHttpHandler _httpHandler;
|
||||
HttpClientNetworkHandler _httpCustomResolverHandler;
|
||||
HttpClient _httpClient;
|
||||
|
||||
#endregion
|
||||
@@ -130,9 +132,12 @@ namespace Failover
|
||||
}
|
||||
}
|
||||
|
||||
if ((_httpCustomResolverHandler is null) || handlerChanged)
|
||||
_httpCustomResolverHandler = new HttpClientNetworkHandler(_httpHandler, _service.DnsServer.PreferIPv6 ? HttpClientNetworkType.PreferIPv6 : HttpClientNetworkType.Default, _service.DnsServer);
|
||||
|
||||
if (_httpClient is null)
|
||||
{
|
||||
HttpClient httpClient = new HttpClient(_httpHandler);
|
||||
HttpClient httpClient = new HttpClient(_httpCustomResolverHandler);
|
||||
|
||||
_httpClient = httpClient;
|
||||
}
|
||||
@@ -140,7 +145,7 @@ namespace Failover
|
||||
{
|
||||
if (handlerChanged)
|
||||
{
|
||||
HttpClient httpClient = new HttpClient(_httpHandler);
|
||||
HttpClient httpClient = new HttpClient(_httpCustomResolverHandler);
|
||||
|
||||
HttpClient oldHttpClient = _httpClient;
|
||||
_httpClient = httpClient;
|
||||
|
||||
Reference in New Issue
Block a user