Skip to content
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

Avoid unnecessary http client creation #618

Open
5 tasks done
jlannoy opened this issue Feb 20, 2024 · 3 comments
Open
5 tasks done

Avoid unnecessary http client creation #618

jlannoy opened this issue Feb 20, 2024 · 3 comments
Labels
feature request A feature has been asked for or suggested by the community

Comments

@jlannoy
Copy link

jlannoy commented Feb 20, 2024

Checklist

  • I have looked into the Readme and Examples, and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Describe the problem you'd like to have solved

Similar to the issue #480, the ManagmentAPI builder set the value of the httpClient to an instantiated http client, which could then be overridden by callers.

Describe the ideal solution

Objects.nonNull(httpClient) ? httpClient : DefaultHttpClient.newBuilder().build() should be used in the build() method.

Alternatives and current workarounds

None.

Additional context

No response

@jlannoy jlannoy added the feature request A feature has been asked for or suggested by the community label Feb 20, 2024
@jlannoy
Copy link
Author

jlannoy commented Feb 20, 2024

Btw, if you could think to an other way to keep the base url in private final HttpUrl baseUrl;(inside AuthAPI and ManagementAPI) it would then be possible to exclude OkHttp3 + Okio dependencies when using an other http client.

@tanya732
Copy link
Contributor

Hi @jlannoy

Thank you so much for bringing this up! We really appreciate your input. Could you please share a bit more detail or an example to help us better understand the issue? I'm not sure, but this change might potentially introduce a breaking change.

Thanks again for your insights!

@jlannoy
Copy link
Author

jlannoy commented Jan 31, 2025

Hello.

In the ManagementAPI class, the Builder at line 405 is instantiating a new client (private Auth0HttpClient httpClient = DefaultHttpClient.newBuilder().build();) even when it's not needed.

Example : if you call new ManagementAPI.Builder("myDomain","myToken").withHttpClient(myOwnClient).build(), a default client has been created for nothing.

The build method should be:

public ManagementAPI build() {
        return new AuthAPI(domain, clientId, clientSecret,
                Objects.nonNull(httpClient) ? httpClient : DefaultHttpClient.newBuilder().build());
}

with the httpClient null by default in the builder, instead of current:

public ManagementAPI build() {
        return new ManagementAPI(domain, SimpleTokenProvider.create(apiToken), httpClient);
}

In fact, it's the exact same change as the issue #480 except that it's for the ManagementAPI class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A feature has been asked for or suggested by the community
Projects
None yet
Development

No branches or pull requests

2 participants