fix bug
This commit is contained in:
parent
224230a226
commit
a5a5ab6986
@ -1,54 +0,0 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FastGithub.Scanner
|
||||
{
|
||||
/// <summary>
|
||||
/// Github的dns解析的httpHandler
|
||||
/// 使扫描索结果作为github的https请求的域名解析
|
||||
/// </summary>
|
||||
[Service(ServiceLifetime.Transient)]
|
||||
sealed class GithubDnsHttpHandler : DelegatingHandler
|
||||
{
|
||||
private readonly GithubScanResults scanResults;
|
||||
|
||||
/// <summary>
|
||||
/// Github的dns解析的httpHandler
|
||||
/// </summary>
|
||||
public GithubDnsHttpHandler(GithubScanResults scanResults)
|
||||
{
|
||||
this.scanResults = scanResults;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送消息
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
var uri = request.RequestUri;
|
||||
if (uri != null && uri.HostNameType == UriHostNameType.Dns)
|
||||
{
|
||||
var address = this.scanResults.FindBestAddress(uri.Host);
|
||||
if (address != null)
|
||||
{
|
||||
var builder = new UriBuilder(uri)
|
||||
{
|
||||
Scheme = Uri.UriSchemeHttp,
|
||||
Host = address.ToString(),
|
||||
Port = 443
|
||||
};
|
||||
request.RequestUri = builder.Uri;
|
||||
request.Headers.Host = uri.Host;
|
||||
}
|
||||
}
|
||||
|
||||
return await base.SendAsync(request, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -86,13 +87,11 @@ namespace FastGithub.Scanner.LookupProviders
|
||||
/// <returns></returns>
|
||||
private async Task<List<IPAddress>> LookupAsync(HttpClient httpClient, string domain, CancellationToken cancellationToken)
|
||||
{
|
||||
var keyValue = new KeyValuePair<string?, string?>("host", domain);
|
||||
var content = new FormUrlEncodedContent(Enumerable.Repeat(keyValue, 1));
|
||||
using var request = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Post,
|
||||
RequestUri = lookupUri,
|
||||
Content = content
|
||||
Content = new StringContent($"host={domain}", Encoding.UTF8, "application/x-www-form-urlencoded")
|
||||
};
|
||||
|
||||
using var response = await httpClient.SendAsync(request, cancellationToken);
|
||||
|
||||
@ -28,7 +28,6 @@ namespace FastGithub
|
||||
services
|
||||
.AddHttpClient(nameof(Scanner))
|
||||
.SetHandlerLifetime(TimeSpan.FromMinutes(5d))
|
||||
.AddHttpMessageHandler<GithubDnsHttpHandler>()
|
||||
.ConfigureHttpClient(httpClient =>
|
||||
{
|
||||
httpClient.Timeout = TimeSpan.FromSeconds(10d);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user