From a46d97467d584819749d9fa2fad2633594d6c47a Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 27 Nov 2025 11:32:14 +0100 Subject: [PATCH] Ensure proper disposal and add HttpExtensions class Updated `InvokeRecActionCommand.cs` to use `using` statements for `HttpClient`, `HttpRequestMessage`, and `HttpResponseMessage` to prevent resource leaks. Added a new `HttpExtensions.cs` file with a static `HttpExtensions` class as a placeholder for future HTTP-related extension methods. Included necessary `using` directives for potential LINQ, collections, and asynchronous programming. --- src/ReC.Application/Common/HttpExtensions.cs | 11 +++++++++++ .../RecActions/Commands/InvokeRecActionCommand.cs | 8 +++----- 2 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 src/ReC.Application/Common/HttpExtensions.cs diff --git a/src/ReC.Application/Common/HttpExtensions.cs b/src/ReC.Application/Common/HttpExtensions.cs new file mode 100644 index 0000000..b24f6b4 --- /dev/null +++ b/src/ReC.Application/Common/HttpExtensions.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ReC.Application.Common; + +public static class HttpExtensions +{ +} diff --git a/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs b/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs index bd56113..431490c 100644 --- a/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs +++ b/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs @@ -1,8 +1,6 @@ using MediatR; using Microsoft.Extensions.Logging; using ReC.Application.Common.Dto; -using System; -using static System.Net.WebRequestMethods; namespace ReC.Application.RecActions.Commands; @@ -25,7 +23,7 @@ public class InvokeRecActionCommandHandler( { public async Task Handle(InvokeRecActionCommand request, CancellationToken cancel) { - var http = clientFactory.CreateClient(); + using var http = clientFactory.CreateClient(); if (request.RestType is null) { @@ -38,9 +36,9 @@ public class InvokeRecActionCommandHandler( } var method = new HttpMethod(request.RestType.ToUpper()); - var msg = new HttpRequestMessage(method, request.EndpointUri); + using var msg = new HttpRequestMessage(method, request.EndpointUri); - var response = await http.SendAsync(msg, cancel); + using var response = await http.SendAsync(msg, cancel); var body = await response.Content.ReadAsStringAsync(cancel); var headers = response.Headers.ToDictionary(); }