@@ -17,8 +17,19 @@ namespace Core.Arango.Transport;
17
17
/// </summary>
18
18
public class ArangoHttpTransport ( IArangoConfiguration configuration ) : IArangoTransport
19
19
{
20
- private readonly string _auth = SetAuth ( configuration ) ;
21
20
private static HttpClient DefaultHttpClient => new ( ) ;
21
+ string _auth = "" ;
22
+ /// <inheritdoc />
23
+ protected string Auth
24
+ {
25
+ get
26
+ {
27
+ if ( string . IsNullOrWhiteSpace ( _auth ) && ! string . IsNullOrWhiteSpace ( configuration . User ) && ! string . IsNullOrWhiteSpace ( configuration . Password ) )
28
+ _auth = Convert . ToBase64String ( Encoding . ASCII . GetBytes ( $ "{ configuration . User } :{ configuration . Password } ") ) ;
29
+ return _auth ;
30
+ }
31
+ }
32
+
22
33
/// <inheritdoc />
23
34
public async Task < T > SendAsync < T > ( HttpMethod m , string url , object body = null ,
24
35
string transaction = null , bool throwOnError = true , bool auth = true ,
@@ -126,21 +137,15 @@ public async Task<HttpContent> SendContentAsync(HttpMethod m, string url, HttpCo
126
137
/// used in requests to ArangoDB.
127
138
/// </summary>
128
139
/// <param name="client"></param>
129
- protected void SetBasicAuth ( HttpClient client ) => client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Basic" , _auth ) ;
140
+ protected void SetBasicAuth ( HttpClient client ) => client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Basic" , Auth ) ;
130
141
131
- static string SetAuth ( IArangoConfiguration configuration )
132
- {
133
- if ( string . IsNullOrWhiteSpace ( configuration . User ) || string . IsNullOrWhiteSpace ( configuration . Password ) )
134
- return string . Empty ;
135
- return Convert . ToBase64String ( Encoding . ASCII . GetBytes ( $ "{ configuration . User } :{ configuration . Password } ") ) ;
136
- }
137
142
private void ApplyHeaders ( string transaction , bool auth , HttpRequestMessage msg ,
138
143
IDictionary < string , string > headers )
139
144
{
140
145
msg . Headers . Add ( HttpRequestHeader . KeepAlive . ToString ( ) , "true" ) ;
141
146
142
- if ( auth && ! string . IsNullOrWhiteSpace ( _auth ) )
143
- msg . Headers . Add ( HttpRequestHeader . Authorization . ToString ( ) , _auth ) ;
147
+ /* if (auth && !string.IsNullOrWhiteSpace(_auth))
148
+ msg.Headers.Add(HttpRequestHeader.Authorization.ToString(), _auth);*/
144
149
145
150
if ( transaction != null )
146
151
msg . Headers . Add ( "x-arango-trx-id" , transaction ) ;
0 commit comments