From daef121bf244794726a275e29ac8c655a7b0ac6c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=99=88=E5=9B=BD=E4=BC=9F?= <366193849@qq.com>
Date: Thu, 30 Sep 2021 08:50:06 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0DomainConfig=E5=B1=9E?=
=?UTF-8?q?=E6=80=A7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
FastGithub.Http/HttpClientFactory.cs | 2 +-
FastGithub.Http/LifetimeHttpHandler.cs | 11 +++++++++--
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/FastGithub.Http/HttpClientFactory.cs b/FastGithub.Http/HttpClientFactory.cs
index 54fbaae..c8e53d6 100644
--- a/FastGithub.Http/HttpClientFactory.cs
+++ b/FastGithub.Http/HttpClientFactory.cs
@@ -75,7 +75,7 @@ namespace FastGithub.Http
private void OnLifetimeHttpHandlerDeactivate(LifetimeHttpHandler lifetimeHttpHandler)
{
// 切换激活状态的记录的实例
- var domainConfig = ((HttpClientHandler)lifetimeHttpHandler.InnerHandler!).DomainConfig;
+ var domainConfig = lifetimeHttpHandler.DomainConfig;
this.httpHandlerLazyCache[domainConfig] = this.CreateLifetimeHttpHandlerLazy(domainConfig);
this.httpHandlerCleaner.Add(lifetimeHttpHandler);
}
diff --git a/FastGithub.Http/LifetimeHttpHandler.cs b/FastGithub.Http/LifetimeHttpHandler.cs
index 3bd6699..8edf8f4 100644
--- a/FastGithub.Http/LifetimeHttpHandler.cs
+++ b/FastGithub.Http/LifetimeHttpHandler.cs
@@ -1,4 +1,5 @@
-using System;
+using FastGithub.Configuration;
+using System;
using System.Net.Http;
using System.Threading;
@@ -11,15 +12,21 @@ namespace FastGithub.Http
{
private readonly Timer timer;
+ ///
+ /// 获取域名配置
+ ///
+ public DomainConfig DomainConfig { get; }
+
///
/// 具有生命周期的HttpHandler
///
/// HttpHandler
/// 拦截器的生命周期
/// 失效回调
- public LifetimeHttpHandler(HttpMessageHandler handler, TimeSpan lifeTime, Action deactivateAction)
+ public LifetimeHttpHandler(HttpClientHandler handler, TimeSpan lifeTime, Action deactivateAction)
: base(handler)
{
+ this.DomainConfig = handler.DomainConfig;
this.timer = new Timer(this.OnTimerCallback, deactivateAction, lifeTime, Timeout.InfiniteTimeSpan);
}