-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Allow to Specify HttpClientHandler in IHttpClientFactory #110009
Comments
Probably a duplicate of, conceptually: Discussions here might be relevant and provide workarounds: |
IMHO allowing configuration of |
@julealgon and @DL444 comments are spot on. If you need to create a new, additional connection with a new certificate to the same server, you are correct that you need a different handler instance -- but that means you need a new named client as well. Because the name corresponds to a shared handle instance. You use a cert name in the snippet -- is this something that can be used? I understand that creating all the configurations for this could be extremely inconvenient, especially if there are lots of different tenants.
From triage perspective, this is a duplicate of #35997 and #36378 I will close the issue in favor of the linked ones, but before that I would like to learn more about the scenario, so I might be able to suggest a suitable workaround. P.S.: Another way to solve this issue -- on a lower level -- might be a concept of sessions for HttpClient. This was discussed in e.g. #77668 and #35992. Same as with certificate, using a different proxy would require a new connection (and a different client name, if HttpClientFactory is used). However, if we introduce something like a Session to incapsulate that, it might greatly simplify the connections and handlers management. |
Hi @CarnaViire , Thanks for your answer. You totally understand the issue. Each instance is in charge of
Thanks in advance |
Background and Motivation
We currently use IHttpClientFactory via dependency injection to generate our HttpClient.
In some of our use cases, we need to define ClientCertificates to connect to the target server. This can only be done by the HttpClientHandler. However, we can only set the right certificate within the scope of the request. So we can't use the HttpClientHandler configured via the DI.
We can create it directly using the HttpClient constructor, but in this case, we lose the configuration performed by the IHttpClientFactory.
We therefore need to dynamically define a handler for an httpClient generated when using an IHttpClientFactory.
Proposed API
Usage Examples
You can use code blocks like this:
Alternative Designs
We are open to other way to go
Risks
As it add a new method endpoint, the risk of regression is minor
The text was updated successfully, but these errors were encountered: