2
0
Эх сурвалжийг харах

默认超时时间2分钟

xljiulang 4 жил өмнө
parent
commit
f95b19d024

+ 5 - 1
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);
 
         /// <summary>
         /// 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);
         }
     }
 }

+ 1 - 3
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);
             }
         }