Skip to content

Commit

Permalink
Added a few usings
Browse files Browse the repository at this point in the history
  • Loading branch information
tippmar-nr committed Dec 19, 2024
1 parent 56a2537 commit cad4f87
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/Agent/NewRelic/Agent/Core/DataTransport/Client/NRHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ public NRHttpClient(IWebProxy proxy, IConfiguration configuration) : base(proxy)
private dynamic GetHttpHandler(IWebProxy proxy)
{
// check whether the application is running .NET 6 or later
// if so, set the pooled connection lifetime to 1 minute
// https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclienthandler.pooledconnectionlifetime?view=net-6.0

if (System.Environment.Version.Major >= 6)
{
try
Expand Down Expand Up @@ -78,12 +75,9 @@ public override IHttpResponse Send(IHttpRequest request)
{
try
{
var req = new HttpRequestMessage
{
RequestUri = request.Uri,
Method = _configuration.PutForDataSend ? HttpMethod.Put : HttpMethod.Post
};

using var req = new HttpRequestMessage();
req.RequestUri = request.Uri;
req.Method = _configuration.PutForDataSend ? HttpMethod.Put : HttpMethod.Post;
req.Headers.Add("User-Agent", $"NewRelic-DotNetAgent/{AgentInstallConfiguration.AgentVersion}");
req.Headers.Add("Connection", "keep-alive");
req.Headers.Add("Keep-Alive", "true");
Expand All @@ -94,7 +88,7 @@ public override IHttpResponse Send(IHttpRequest request)
req.Headers.Add(header.Key, header.Value);
}

var content = new ByteArrayContent(request.Content.PayloadBytes);
using var content = new ByteArrayContent(request.Content.PayloadBytes);
var encoding = request.Content.IsCompressed ? request.Content.CompressionType.ToLower() : "identity";
content.Headers.ContentType = new MediaTypeHeaderValue(request.Content.ContentType);
content.Headers.Add("Content-Encoding", encoding);
Expand All @@ -108,7 +102,7 @@ public override IHttpResponse Send(IHttpRequest request)
}

Log.Finest($"Request({request.RequestGuid}: Sending");
var response = _httpClientWrapper.SendAsync(req).GetAwaiter().GetResult();
using var response = _httpClientWrapper.SendAsync(req).GetAwaiter().GetResult();
Log.Finest($"Request({request.RequestGuid}: Sent");

var httpResponse = new HttpResponse(request.RequestGuid, response);
Expand Down

0 comments on commit cad4f87

Please sign in to comment.