diff --git a/FastGithub.ReverseProxy/ReverseProxyApplicationBuilderExtensions.cs b/FastGithub.ReverseProxy/ReverseProxyApplicationBuilderExtensions.cs index 1325192..28eb2f9 100644 --- a/FastGithub.ReverseProxy/ReverseProxyApplicationBuilderExtensions.cs +++ b/FastGithub.ReverseProxy/ReverseProxyApplicationBuilderExtensions.cs @@ -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); } diff --git a/FastGithub.Scanner/GithubHttpClientHanlder.cs b/FastGithub.Scanner/GithubHttpClientHanlder.cs index 03c7855..48efc7f 100644 --- a/FastGithub.Scanner/GithubHttpClientHanlder.cs +++ b/FastGithub.Scanner/GithubHttpClientHanlder.cs @@ -72,7 +72,7 @@ namespace FastGithub.Scanner /// - /// 查找最快的ip来发送消息 + /// 替换github域名为ip /// /// /// @@ -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 /// /// 解析域名 + /// 非github域名返回null /// /// /// - 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 => { diff --git a/FastGithub.Scanner/LookupProviders/GithubMetaProvider.cs b/FastGithub.Scanner/LookupProviders/GithubMetaProvider.cs index 62ddba8..7a92af2 100644 --- a/FastGithub.Scanner/LookupProviders/GithubMetaProvider.cs +++ b/FastGithub.Scanner/LookupProviders/GithubMetaProvider.cs @@ -92,7 +92,7 @@ namespace FastGithub.Scanner.LookupProviders catch (Exception) { cancellationToken.ThrowIfCancellationRequested(); - this.logger.LogWarning($"使用{metaUri}的副本数据"); + this.logger.LogWarning($"使用副本数据{metaUri}"); return await httpClient.GetFromJsonAsync(metaUri, cancellationToken); } }