Skip to content

Commit f257ad5

Browse files
committed
fix avoid creating a client for each request in hidi
Signed-off-by: Vincent Biret <[email protected]>
1 parent 205fec1 commit f257ad5

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/Microsoft.OpenApi.Hidi/OpenApiService.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,11 @@ private static Dictionary<string, List<string>> EnumerateJsonDocument(JsonElemen
492492
return paths;
493493
}
494494

495+
private static readonly Lazy<HttpClient> httpClient = new(() => new HttpClient()
496+
{
497+
DefaultRequestVersion = HttpVersion.Version20
498+
});
499+
495500
/// <summary>
496501
/// Reads stream from file system or makes HTTP request depending on the input string
497502
/// </summary>
@@ -507,11 +512,7 @@ private static async Task<Stream> GetStreamAsync(string input, ILogger logger, C
507512
{
508513
try
509514
{
510-
using var httpClient = new HttpClient
511-
{
512-
DefaultRequestVersion = HttpVersion.Version20
513-
};
514-
stream = await httpClient.GetStreamAsync(new Uri(input), cancellationToken).ConfigureAwait(false);
515+
stream = await httpClient.Value.GetStreamAsync(new Uri(input), cancellationToken).ConfigureAwait(false);
515516
}
516517
catch (HttpRequestException ex)
517518
{

0 commit comments

Comments
 (0)