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.
This commit is contained in:
parent
2f3a685e7d
commit
a46d97467d
11
src/ReC.Application/Common/HttpExtensions.cs
Normal file
11
src/ReC.Application/Common/HttpExtensions.cs
Normal file
@ -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
|
||||
{
|
||||
}
|
||||
@ -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();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user