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