Add support for HTTP client managed by AcmeProvider#180
Draft
hslatman wants to merge 3 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey @shred,
I'm currently working on an Android app that is going to interact with step-ca.
acme4jgot me very close to a complete ACME flow, but I had to remove the dependency on some usages ofjava.net.http.HttpClient(.Builder)from the flow to make it work.This draft PR contains the minimal changes I needed to make the app compile and run. I've opened it early to gauge whether or not you're open to the suggested changes.
The most important bit is that an
AcmeProvidercan now optionally implementAcmeProviderManagingHttpClient(naming suggestion welcome), meaning that it gets full control and responsibility over the HTTP client, instead of using the single, shared instance stored on theSession. This allows an implementation ofAcmeProviderto use a totally different HTTP client backing theConnection. I've successfully tested it withOkHttp, but other libraries should work too.I believe the changes in this PR aren't only useful to someone building an Android app; I can also see it being used for when more control over the HTTP client is required, or when a different HTTP library is used in a project for other purposes. The changes from this PR allow
acme4jto play nice with the existing HTTP library in that case.One caveat with the current changes is that accessing the
networkSettings.proxySelectorwill result in a runtime error, as it'll try to referenceHttpClient.Builder.NO_PROXY. Also,ProxySelector.ofdidn't seem available to me, so just replacingNO_PROXYisn't an option. Managing the proxy settings in a concrete implementation ofAcmeProviderManagingHttpClientshould thus not depend on what's passed vianetworkSettings.I thought about a more involved refactoring that would allow injecting a custom HTTP client, specifically meant for just ACME requests/responses. By default it would be backed by
java.net.http.HttpClient, but it would allow one to provide a different implementation. I figured I'd go for the smallest diff first.Happy to hear feedback on the suggested changes 😄