diff --git a/README.md b/README.md
index 00542ad3..060982d5 100644
--- a/README.md
+++ b/README.md
@@ -142,20 +142,33 @@ VaultConfiguration config = new VaultConfiguration("http:127.0.0.1:8200");
VaultClient vaultClient = new VaultClient(config);
```
-You can also add custom configuration including a custom `HttpClientHandler`.
-This can be used to intercept requests and add custom logic before the base
-`SendAsync` is called by the HttpClient. See [HttpClientHandler docs][http-client-handler-docs] for more details.
+We also allow you to bring your own `HttpClient` through a delegate. This can work
+with any current factory pattern that you're using to create an `HttpClient`
+object, which is one of the recommended patterns for managing your `HttpClient`
+lifecycle. More on the `IHttpClientFactory` can be found [here][[http-client-factory]]
```csharp
-// Create a custom HttpClientHandler
-HttpClientHandler myClientHandler = new HttpClientHandler();
+// Create a HttpClient Provider Function
+ public static HttpClient MyHttpClientProvider(HttpClientHandler handler)
+ {
+ // Configuring your own HttpClient
+ HttpClient httpClient = new HttpClient(handler);
+ httpClient.Timeout = TimeSpan.FromSeconds(60);
+ return httpClient;
+ }
+```
+```csharp
+// Configuring Vault with your custom HttpClient Provider
VaultConfiguration config = new VaultConfiguration("http://127.0.0.1:8200",
- myClientHandler);
+ httpClientProvider: MyHttpClientProvider);
```
The VaultClient also allows you to set a custom Timeout for all API calls.
+_**Note**_: This timeout will override any timeout in a preconfigured `HttpClient`
+
+
```csharp
VaultConfiguration config = new VaultConfiguration(basePath: address,
httpClientHandler: httpClientHandler,
diff --git a/generate/templates/Configuration.mustache b/generate/templates/Configuration.mustache
index 55c1adee..1a3a5e76 100644
--- a/generate/templates/Configuration.mustache
+++ b/generate/templates/Configuration.mustache
@@ -15,7 +15,7 @@ using System.Security.Cryptography.X509Certificates;
using System.Text;
namespace {{packageName}}.Client
-{
+{
///
/// Represents the TLS Configuration
///
@@ -168,17 +168,17 @@ namespace {{packageName}}.Client
#region Constructors
///
- /// Initializes a new instance of the class
+ /// Initializes a new instance of the class
///
- public {{packageName}}Configuration(string basePath,
- HttpClientHandler httpClientHandler = null,
+ public VaultConfiguration(string basePath,
+ Func httpClientProvider = null,
TimeSpan? timeout = null,
RetryConfiguration retryConfiguration = null,
RateLimitConfiguration rateLimitConfiguration = null,
TLSConfiguration tlsConfiguration = null)
{
if (string.IsNullOrEmpty(basePath)) throw new ArgumentException("Cannot be empty", "BasePath");
- HttpClientHandler = httpClientHandler ?? new HttpClientHandler();
+ HttpClientHandler = new HttpClientHandler();
if (tlsConfiguration != null)
{
@@ -189,7 +189,7 @@ namespace {{packageName}}.Client
{
throw new ArgumentException("Certificate does not contain a private key");
}
- httpClientHandler.ClientCertificates.Add(TLSConfiguration.ClientCertificate);
+ HttpClientHandler.ClientCertificates.Add(TLSConfiguration.ClientCertificate);
}
else if (TLSConfiguration.ClientCertificateCollection != null)
{
@@ -201,7 +201,7 @@ namespace {{packageName}}.Client
}
}
- httpClientHandler.ClientCertificates.AddRange(TLSConfiguration.ClientCertificateCollection);
+ HttpClientHandler.ClientCertificates.AddRange(TLSConfiguration.ClientCertificateCollection);
}
Func