Skip to content

Add support for HTTP client managed by AcmeProvider#180

Draft
hslatman wants to merge 3 commits into
shred:masterfrom
hslatman:managed-http-client
Draft

Add support for HTTP client managed by AcmeProvider#180
hslatman wants to merge 3 commits into
shred:masterfrom
hslatman:managed-http-client

Conversation

@hslatman

@hslatman hslatman commented Jun 9, 2026

Copy link
Copy Markdown

Hey @shred,

I'm currently working on an Android app that is going to interact with step-ca. acme4j got me very close to a complete ACME flow, but I had to remove the dependency on some usages of java.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 AcmeProvider can now optionally implement AcmeProviderManagingHttpClient (naming suggestion welcome), meaning that it gets full control and responsibility over the HTTP client, instead of using the single, shared instance stored on the Session. This allows an implementation of AcmeProvider to use a totally different HTTP client backing the Connection. I've successfully tested it with OkHttp, 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 acme4j to play nice with the existing HTTP library in that case.

One caveat with the current changes is that accessing the networkSettings.proxySelector will result in a runtime error, as it'll try to reference HttpClient.Builder.NO_PROXY. Also, ProxySelector.of didn't seem available to me, so just replacing NO_PROXY isn't an option. Managing the proxy settings in a concrete implementation of AcmeProviderManagingHttpClient should thus not depend on what's passed via networkSettings.

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 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant