Skip to content

Commit ac5a04c

Browse files
author
PalashKarmaker
committed
chanfes
1 parent fa05e01 commit ac5a04c

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

Core.Arango/Transport/ArangoHttpTransport.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ namespace Core.Arango.Transport;
2020
/// </summary>
2121
public class ArangoHttpTransport(IArangoConfiguration configuration) : IArangoTransport
2222
{
23-
private static readonly HttpClient DefaultHttpClient = new();
23+
static readonly HttpClient DefaultHttpClient = new();
24+
HttpClient Client => configuration.HttpClient ?? DefaultHttpClient;
2425
string _auth = "";
2526
DateTime _authValidUntil = DateTime.MinValue;
2627
/// <inheritdoc />
@@ -73,9 +74,8 @@ public async Task<T> SendAsync<T>(HttpMethod m, string url, object body = null,
7374
}
7475
else
7576
req.Headers.Add(HttpRequestHeader.ContentLength.ToString(), "0");
76-
var httpClient = DefaultHttpClient;
77-
SetBasicAuth(httpClient);
78-
using var res = await httpClient.SendAsync(req, cancellationToken).ConfigureAwait(false);
77+
SetBasicAuth(Client);
78+
using var res = await Client.SendAsync(req, cancellationToken).ConfigureAwait(false);
7979

8080
if (!res.IsSuccessStatusCode)
8181
if (throwOnError)
@@ -121,9 +121,8 @@ public async Task<object> SendAsync(Type type, HttpMethod m, string url, object
121121
}
122122
else
123123
req.Headers.Add(HttpRequestHeader.ContentLength.ToString(), "0");
124-
var httpClient = DefaultHttpClient;
125-
SetBasicAuth(httpClient);
126-
using var res = await httpClient.SendAsync(req, cancellationToken).ConfigureAwait(false);
124+
SetBasicAuth(Client);
125+
using var res = await Client.SendAsync(req, cancellationToken).ConfigureAwait(false);
127126

128127
if (!res.IsSuccessStatusCode)
129128
if (throwOnError)
@@ -149,9 +148,8 @@ public async Task<HttpContent> SendContentAsync(HttpMethod m, string url, HttpCo
149148
using var req = new HttpRequestMessage(m, configuration.Server + url);
150149
ApplyHeaders(transaction, auth, req, headers);
151150
req.Content = body;
152-
var httpClient = DefaultHttpClient;
153-
SetBasicAuth(httpClient);
154-
using var res = await httpClient.SendAsync(req, cancellationToken);
151+
SetBasicAuth(Client);
152+
using var res = await Client.SendAsync(req, cancellationToken);
155153

156154
if (!res.IsSuccessStatusCode && throwOnError)
157155
{

0 commit comments

Comments
 (0)