From 5c7145c056cfb189fb8958c3452f1caa714394e9 Mon Sep 17 00:00:00 2001 From: xljiulang <366193849@qq.com> Date: Thu, 12 Aug 2021 22:40:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E7=94=A8Timeout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastGithub.Http/HttpClientHandler.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/FastGithub.Http/HttpClientHandler.cs b/FastGithub.Http/HttpClientHandler.cs index 2d839f1..4dedf28 100644 --- a/FastGithub.Http/HttpClientHandler.cs +++ b/FastGithub.Http/HttpClientHandler.cs @@ -21,7 +21,6 @@ namespace FastGithub.Http { private readonly DomainConfig domainConfig; private readonly IDomainResolver domainResolver; - private readonly TimeSpan defaltTimeout = TimeSpan.FromMinutes(2d); /// /// HttpClientHandler @@ -76,11 +75,18 @@ namespace FastGithub.Http } request.RequestUri = uriBuilder.Uri; - using var timeoutTokenSource = new CancellationTokenSource(this.domainConfig.Timeout ?? defaltTimeout); - using var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutTokenSource.Token); - return await base.SendAsync(request, cancellationToken); - } + if (this.domainConfig.Timeout != null) + { + using var timeoutTokenSource = new CancellationTokenSource(this.domainConfig.Timeout.Value); + using var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutTokenSource.Token); + return await base.SendAsync(request, linkedTokenSource.Token); + } + else + { + return await base.SendAsync(request, cancellationToken); + } + } /// /// 创建转发代理的httpHandler