Skip to content

Commit

Permalink
Temporary Fix for v3 Timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
dvonthenen committed Feb 5, 2024
1 parent e735bfa commit 476f508
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 47 deletions.
7 changes: 5 additions & 2 deletions Deepgram/Deepgram.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
<PackageTags>speech-to-text,captions,speech-recognition,deepgram</PackageTags>
<PackageIcon>dg_logo.png</PackageIcon>
<Product>Deepgram.NET SDK</Product>
<PackageId>Deepgram</PackageId>
<Title>Deepgram.NET</Title>
<PackageId>Deepgram .NET SDK</PackageId>
<Title>Deepgram .NET SDK</Title>
<Version>3.4.1</Version>
<Authors>Deepgram Contributors</Authors>
<Company />
</PropertyGroup>

<ItemGroup>
Expand Down
83 changes: 38 additions & 45 deletions Deepgram/Utilities/HttpClientUtil.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,38 @@
using System;
using System.Net.Http;
using System.Net.Http.Headers;

namespace Deepgram.Utilities
{
public class HttpClientUtil
{
// Client used in instance when needed
internal HttpClient HttpClient { get; private set; }

internal HttpClientUtil() {
HttpClient = Create();
}

/// <summary>
/// Create a Httpclient set common headers
/// </summary>
/// <returns></returns>
private HttpClient Create()
{
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgentUtil.GetUserAgent());

return httpClient;
}

/// <summary>
/// sets timeout on the httpclient
/// </summary>
/// <param name="timeSpan"></param>
public void SetTimeOut(TimeSpan timeSpan)
{
// If the timeout has a new value, create a new HttpClient
if (HttpClient.Timeout != timeSpan)
{
HttpClient = Create();
}

// Set the timeout
HttpClient.Timeout = timeSpan;
}
}
}
using System;
using System.Net.Http;
using System.Net.Http.Headers;

namespace Deepgram.Utilities
{
public class HttpClientUtil
{
// Client used in instance when needed
internal HttpClient HttpClient { get; private set; }

internal HttpClientUtil() {
HttpClient = Create();
}

/// <summary>
/// Create a Httpclient set common headers
/// </summary>
/// <returns></returns>
private HttpClient Create()
{
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgentUtil.GetUserAgent());

return httpClient;
}

/// <summary>
/// sets timeout on the httpclient
/// </summary>
/// <param name="timeSpan"></param>
public void SetTimeOut(TimeSpan timeSpan)
{
HttpClient.Timeout = timeSpan;
}
}
}

0 comments on commit 476f508

Please sign in to comment.