默认超时时间2分钟

This commit is contained in:
xljiulang 2021-07-24 11:56:37 +08:00
parent bd4133aa2c
commit f95b19d024
2 changed files with 6 additions and 4 deletions

View File

@ -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);
}
}
}

View File

@ -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);
}
}