diff --git a/RqliteDotnet/RqliteClient.cs b/RqliteDotnet/RqliteClient.cs
index d69745a..7621886 100644
--- a/RqliteDotnet/RqliteClient.cs
+++ b/RqliteDotnet/RqliteClient.cs
@@ -8,9 +8,20 @@ public class RqliteClient : IRqliteClient
{
private readonly HttpClient _httpClient;
- public RqliteClient(string uri, HttpClient? client = null)
+ ///
+ /// Returns new RqliteClient
+ ///
+ /// URI where rqlite instance is running
+ /// Http client to use instead of default one
+ /// Basic auth string (username:password) that is base64 encoded and sent in Authorization header. If empty the header is not sent
+ public RqliteClient(string uri, HttpClient? client = null, string basicAuthInfo = "")
{
_httpClient = client ?? new HttpClient(){ BaseAddress = new Uri(uri) };
+ if (!string.IsNullOrEmpty(basicAuthInfo))
+ {
+ var encoded = Convert.ToBase64String(Encoding.UTF8.GetBytes(basicAuthInfo));
+ _httpClient.DefaultRequestHeaders.Add("Authorization", $"Basic {encoded}");
+ }
}
public RqliteClient(HttpClient client)
diff --git a/RqliteDotnet/RqliteOrmClient.cs b/RqliteDotnet/RqliteOrmClient.cs
index e792417..bd1337c 100644
--- a/RqliteDotnet/RqliteOrmClient.cs
+++ b/RqliteDotnet/RqliteOrmClient.cs
@@ -5,8 +5,6 @@ namespace RqliteDotnet;
public class RqliteOrmClient : RqliteClient, IRqliteOrmClient
{
- public RqliteOrmClient(HttpClient client) : base(client) { }
-
public RqliteOrmClient(string uri, HttpClient? client = null) : base(uri, client) {}
///
diff --git a/RqliteDotnetExample/Program.cs b/RqliteDotnetExample/Program.cs
index 8fabb49..92813ca 100644
--- a/RqliteDotnetExample/Program.cs
+++ b/RqliteDotnetExample/Program.cs
@@ -5,9 +5,10 @@ namespace RqliteDotnetExample;
public static class RqliteDotnetExample
{
- public static void Main(string[] args)
+ public static async Task Main(string[] args)
{
var x = new RqliteClient("http://localhost:4001");
- Console.WriteLine(x.Ping().Result);
+ var ping = await x.Ping();
+ Console.WriteLine(ping);
}
}
\ No newline at end of file