diff --git a/src/Docfx.Build.Engine/XRefMaps/XRefMapDownloader.cs b/src/Docfx.Build.Engine/XRefMaps/XRefMapDownloader.cs index 24391f3edac..05d10b92deb 100644 --- a/src/Docfx.Build.Engine/XRefMaps/XRefMapDownloader.cs +++ b/src/Docfx.Build.Engine/XRefMaps/XRefMapDownloader.cs @@ -125,7 +125,12 @@ protected static async Task DownloadFromWebAsync(Uri uri) var baseUrl = uri.GetLeftPart(UriPartial.Path); baseUrl = baseUrl.Substring(0, baseUrl.LastIndexOf('/') + 1); - using var httpClient = new HttpClient(new HttpClientHandler() { CheckCertificateRevocationList = true }); + bool.TryParse(Environment.GetEnvironmentVariable("DOCFX_NO_CHECK_CERTIFICATE_REVOCATION_LIST"), out var noCheckCertificateRevocationList); + using var httpClient = new HttpClient(new HttpClientHandler() + { + CheckCertificateRevocationList = !noCheckCertificateRevocationList + }); + using var stream = await httpClient.GetStreamAsync(uri); using var sr = new StreamReader(stream); var map = YamlUtility.Deserialize(sr); diff --git a/src/Docfx.Build.Engine/XrefClient.cs b/src/Docfx.Build.Engine/XrefClient.cs deleted file mode 100644 index 817e65c8c64..00000000000 --- a/src/Docfx.Build.Engine/XrefClient.cs +++ /dev/null @@ -1,84 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Net.Http.Headers; - -using Docfx.Common; -using Docfx.Plugins; - -namespace Docfx.Build.Engine; - -public class XrefClient -{ - public static readonly XrefClient Default = new(); - private static readonly HttpClient _sharedClient = - new Func(() => - { - var client = new HttpClient(new HttpClientHandler { CheckCertificateRevocationList = true }); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - return client; - })(); - private readonly HttpClient _client; - private readonly SemaphoreSlim _semaphore; - - public XrefClient() - : this(_sharedClient, null) { } - - public XrefClient(HttpClient client) - : this(null, null) { } - - public XrefClient(int maxParallelism) - : this(null, new SemaphoreSlim(maxParallelism)) { } - - public XrefClient(SemaphoreSlim semaphore) - : this(null, semaphore) { } - - public XrefClient(HttpClient client, int maxParallelism) - : this(client, new SemaphoreSlim(maxParallelism)) { } - - public XrefClient(HttpClient client, SemaphoreSlim semaphore) - { - _client = client ?? _sharedClient; - _semaphore = semaphore; - } - - public async Task> ResolveAsync(string url) - { - if (_semaphore == null) - { - return await ResolveCoreAsync(url); - } - await _semaphore.WaitAsync(); - try - { - return await ResolveCoreAsync(url); - } - finally - { - if (_semaphore != null) - { - _semaphore.Release(); - } - } - } - - private async Task> ResolveCoreAsync(string url) - { - using var stream = await _client.GetStreamAsync(url); - using var sr = new StreamReader(stream); - var xsList = JsonUtility.Deserialize>>(sr); - return xsList.ConvertAll(item => - { - var spec = new XRefSpec(); - foreach (var pair in item) - { - if (pair.Value is string s) - { - spec[pair.Key] = s; - } - } - return spec; - }); - } -}