-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add delegate for HttpClient override #64
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ using System.Security.Cryptography.X509Certificates; | |
using System.Text; | ||
|
||
namespace {{packageName}}.Client | ||
{ | ||
{ | ||
/// <summary> | ||
/// Represents the TLS Configuration | ||
/// </summary> | ||
|
@@ -168,17 +168,17 @@ namespace {{packageName}}.Client | |
|
||
#region Constructors | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="{{packageName}}Configuration" /> class | ||
/// Initializes a new instance of the <see cref="VaultConfiguration" /> class | ||
/// </summary> | ||
public {{packageName}}Configuration(string basePath, | ||
HttpClientHandler httpClientHandler = null, | ||
public VaultConfiguration(string basePath, | ||
Func<HttpClientHandler, HttpClient> httpClientProvider = null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is I saw There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, this is kind of weird. But because the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was debating whether to allow just to pass their own It could be that we offer both options. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the Go version, we allow you to provide HTTPClient directly but then override the TLS options (if configured). Not sure if this is something doable here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this make sense in the context of IHttpClientFactory, as the factory manages the HttpClientHandler instances? |
||
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<object, X509Certificate, X509Chain, SslPolicyErrors, bool> ValidateServiceCertficate = | ||
|
@@ -225,17 +225,17 @@ namespace {{packageName}}.Client | |
return true; | ||
}; | ||
|
||
httpClientHandler.ClientCertificateOptions = ClientCertificateOption.Manual; | ||
httpClientHandler.ServerCertificateCustomValidationCallback = ValidateServiceCertficate; | ||
HttpClientHandler.ClientCertificateOptions = ClientCertificateOption.Manual; | ||
HttpClientHandler.ServerCertificateCustomValidationCallback = ValidateServiceCertficate; | ||
} | ||
|
||
|
||
timeout = timeout ?? TimeSpan.FromSeconds(100); | ||
RetryConfiguration = retryConfiguration ?? new RetryConfiguration(5, TimeSpan.FromMilliseconds(500)); | ||
RateLimitConfiguration = rateLimitConfiguration ?? new RateLimitConfiguration(50, TimeSpan.FromSeconds(5)); | ||
|
||
BasePath = basePath.EndsWith("/") ? basePath : basePath + "/"; | ||
HttpClient = new HttpClient(HttpClientHandler); | ||
|
||
HttpClient = httpClientProvider == null ? new HttpClient(HttpClientHandler) : httpClientProvider(HttpClientHandler); | ||
timeout = timeout ?? TimeSpan.FromSeconds(100); | ||
HttpClient.Timeout = (TimeSpan)timeout; | ||
} | ||
|
||
|
@@ -246,7 +246,7 @@ namespace {{packageName}}.Client | |
/// <summary> | ||
/// Gets or sets the base path for API access. | ||
/// </summary> | ||
public virtual string BasePath | ||
public virtual string BasePath | ||
{ | ||
get { return _basePath; } | ||
set { _basePath = value; } | ||
|
@@ -344,7 +344,7 @@ namespace {{packageName}}.Client | |
|
||
return apiKeyValue; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the access token for OAuth2 authentication. | ||
/// | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad link?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh whooops