-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dvonthenen
committed
Feb 5, 2024
1 parent
e735bfa
commit 476f508
Showing
2 changed files
with
43 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |