-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[csharp][netcore-httpclient] Reuse HttpClient, Allow use of external HttpClient. Patch to previous PR. #9109
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
Conversation
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
Looked over it real quick, looks fine from a code standpoint on first glance. We should discuss whether we really want to just assume that having these features missing is going to be noticed by users and having the info in the readme itself is going to be fine. I'm not even sure how many people know about the handler in the first place. Though I do get it makes for much easier usage and maybe proxy, cookies and client certificates are special use cases anyway. We could throw exceptions when those features are used and no handler is set. That would be another way to do things. |
You are right, I removed the disable feature parameter because it was 1:1 related with the handler, but I understood your idea to ask the permission to disable some features.
Seeing that nobody has view the issue I could say not a lot of people. An issue that you can see in a real production scenario, nothing you can easily test here. Thinking about my usage in the Net Core, the base documentation is clear and cover a few but detailed points, one is the DI and its features. One of that is the HttpClient and its handlers lifcecyle, plus a resilient integration with Polly for retries, caching. The handlers are pooled, and you recieve a configured, working HttpClient, not the handler.
Its a good idea, they depends a lot on the configuration so probably they will not comes out easily at coding time, but in some customer settings during the production setup. I still prefer to have a clear error probaly than a silent behavior. |
Think about to remove the handler\clients from local variables and from method signature and use them as class fields as they are now. |
Yeah, do that change, its a leftover from when they were created locally. |
I'd say do that then. Introduce an exception with "Operation not supported" or something like that, including a useful error message. That of course doesn't work for the extraction of cookies in the ToApiResponse part, but I think we can leave that one. |
Sorry I closed for error |
I don't know maybe the check can be made at constructor time when you have both handler valued and the configuration with something not supported. I have too many doubt on the configuration, I see is passed\merged at ctor but is also used in the call passing it from the outside so I cannot do that. What type of exception is more adapt to the client? |
…ed for the constructor
I think InvalidOperationException or NotSupportedException both kind of fit. In general yeah I think the csharp surface needs a bit of a rework, as its used by the generated code I think the generation never is used after the initial client setup. So maybe I'll rework that afterwards as well. |
Looks good to me. I like having exceptions in just these specific cases where it actually matters. So good to be merged from my points of view. |
Circle CI failure (not related to this change) already fixed in the master |
@lucamazzanti when you've time, can you please PM me via https://join.slack.com/t/openapi-generator/shared_invite/enQtNzAyNDMyOTU0OTE1LTY5ZDBiNDI5NzI5ZjQ1Y2E5OWVjMjZkYzY1ZGM2MWQ4YWFjMzcyNDY5MGI4NjQxNDBiMTlmZTc5NjY2ZTQ5MGM to discuss a little bit more about your use case? Thank you. |
Thanks you all for the project and the support |
Done |
So this merge will be released in milestone 5.1.1, I'll test it and move in production after the release. |
I might be doing another pull request to clean up the huge amount of constructors we have right now. I think we can boil those down a bit. |
I understand there are so many constructors. |
Created PR #9145 to reduce the number of constructors. |
Fixed an existing issue that made the HttpClient open new sockets for each connection.
Also makes HttpClient settable from external.
Fixes: #9060
Patches: #9085
Updated constructors to be more explicit in the usage.
Updated documentation to underline the use cases and the issue.
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.For Windows users, please run the script in Git BASH.
master
,5.1.x
,6.0.x
@mandrean (2017/08) @frankyjuang (2019/09) @shibayan (2020/02) @Blackclaws (2021/03)