fix bug
This commit is contained in:
parent
0bcce75cb8
commit
64596e7656
@ -33,7 +33,7 @@ namespace FastGithub
|
||||
else
|
||||
{
|
||||
var port = context.Request.Host.Port ?? 443;
|
||||
var destinationPrefix = $"http://{host}:{port}/";
|
||||
var destinationPrefix = $"https://{host}:{port}/";
|
||||
var httpClient = new HttpMessageInvoker(httpClientHanlder, disposeHandler: false);
|
||||
await httpForwarder.SendAsync(context, destinationPrefix, httpClient);
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ namespace FastGithub.Scanner
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查找最快的ip来发送消息
|
||||
/// 替换github域名为ip
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
@ -82,12 +82,14 @@ namespace FastGithub.Scanner
|
||||
var uri = request.RequestUri;
|
||||
if (uri != null && uri.HostNameType == UriHostNameType.Dns)
|
||||
{
|
||||
var address = this.Resolve(uri.Host);
|
||||
if (address != null)
|
||||
var githubAddress = this.ResolveGithub(uri.Host);
|
||||
if (githubAddress != null)
|
||||
{
|
||||
var builder = new UriBuilder(uri)
|
||||
{
|
||||
Host = address.ToString()
|
||||
Scheme = Uri.UriSchemeHttp,
|
||||
Host = githubAddress.ToString(),
|
||||
Port = 443
|
||||
};
|
||||
request.RequestUri = builder.Uri;
|
||||
request.Headers.Host = uri.Host;
|
||||
@ -99,10 +101,11 @@ namespace FastGithub.Scanner
|
||||
|
||||
/// <summary>
|
||||
/// 解析域名
|
||||
/// 非github域名返回null
|
||||
/// </summary>
|
||||
/// <param name="domain"></param>
|
||||
/// <returns></returns>
|
||||
private IPAddress? Resolve(string domain)
|
||||
private IPAddress? ResolveGithub(string domain)
|
||||
{
|
||||
// 非github的域名,返回null走上游dns
|
||||
if (this.githubResolver.IsSupported(domain) == false)
|
||||
@ -110,6 +113,7 @@ namespace FastGithub.Scanner
|
||||
return default;
|
||||
}
|
||||
|
||||
// 缓存1s,避免做为公共服务后不必要的并发查询
|
||||
var key = $"domain:{domain}";
|
||||
var address = this.memoryCache.GetOrCreate(key, e =>
|
||||
{
|
||||
|
||||
@ -92,7 +92,7 @@ namespace FastGithub.Scanner.LookupProviders
|
||||
catch (Exception)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
this.logger.LogWarning($"使用{metaUri}的副本数据");
|
||||
this.logger.LogWarning($"使用副本数据{metaUri}");
|
||||
return await httpClient.GetFromJsonAsync<Meta>(metaUri, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user