diff --git a/FastGithub.Http/HttpClient.cs b/FastGithub.Http/HttpClient.cs index 8a8d4c5..498063b 100644 --- a/FastGithub.Http/HttpClient.cs +++ b/FastGithub.Http/HttpClient.cs @@ -11,6 +11,7 @@ namespace FastGithub.Http public class HttpClient : HttpMessageInvoker { private readonly DomainConfig domainConfig; + private readonly TimeSpan defaltTimeout = TimeSpan.FromMinutes(2d); /// /// http客户端 @@ -50,7 +51,10 @@ namespace FastGithub.Http TlsSniPattern = this.domainConfig.GetTlsSniPattern(), TlsIgnoreNameMismatch = this.domainConfig.TlsIgnoreNameMismatch }); - return base.SendAsync(request, cancellationToken); + + using var timeoutTokenSource = new CancellationTokenSource(this.domainConfig.Timeout ?? defaltTimeout); + using var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutTokenSource.Token); + return base.SendAsync(request, linkedTokenSource.Token); } } } \ No newline at end of file diff --git a/FastGithub.ReverseProxy/ReverseProxyMiddleware.cs b/FastGithub.ReverseProxy/ReverseProxyMiddleware.cs index 88008c0..4429472 100644 --- a/FastGithub.ReverseProxy/ReverseProxyMiddleware.cs +++ b/FastGithub.ReverseProxy/ReverseProxyMiddleware.cs @@ -56,9 +56,7 @@ namespace FastGithub.ReverseProxy { var destinationPrefix = GetDestinationPrefix(host, domainConfig.Destination); var httpClient = this.httpClientFactory.CreateHttpClient(domainConfig); - var requestConfig = new ForwarderRequestConfig { Timeout = domainConfig.Timeout }; - - var error = await httpForwarder.SendAsync(context, destinationPrefix, httpClient, requestConfig); + var error = await httpForwarder.SendAsync(context, destinationPrefix, httpClient); await HandleErrorAsync(context, error); } }