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

Accept a HttpClient.Builder Supplier (Http Module) #102

Closed
akefirad opened this issue May 17, 2024 · 5 comments · Fixed by #104
Closed

Accept a HttpClient.Builder Supplier (Http Module) #102

akefirad opened this issue May 17, 2024 · 5 comments · Fixed by #104

Comments

@akefirad
Copy link

If I understand this correctly, the code (com.agorapulse.gru.http.Http#run) creates a builder directly inside the method. And there's no way for the developer to override the HttpClient implementation. One use case is to be able to log request/response bodies (which is impossible using the existing functionalities). Would be nice to accept a Supplier<HttpClient.Builder> or some other mechanism to be able to override the exact concrete implementation of the HttpClient.

@musketyr
Copy link
Collaborator

hi, com.agorapulse.gru.http.Http#run is a framework method and it's not supposed to be run by the developers directly. you can customize the client when creating it using com.agorapulse.gru.http.Http#create(java.lang.Object, java.util.function.Consumer<java.net.http.HttpClient.Builder>)

@akefirad
Copy link
Author

It seems I was not clear. Let me try again. I’d like to control what type of Builder is used. What I need cannot be achieved via customizing the builder (e.g. logging request and response body which seems to be possible only by extending the underlying client). I was referencing the run method just point out where the limitation comes from. Not intention to use it.

@musketyr
Copy link
Collaborator

Thanks for clarification but I think I'm still not on the same page.

Can you add some more detailed example?

@akefirad
Copy link
Author

OK, what's my problem? I'd like to log request and response bodies fully. For OkHttp it's as simple as just adding the logging interceptor. But for JDK HttpClient, it's not possible. It provide some logging but very ugly and don't log request/response bodies. Now, interestingly (unfortunately) it doesn't seem to be easily possible to achieve this by "just customizing" the client. One solution people suggested is to extend the HttpClient class and change its behavior. But do be able to do that, I need to ask Gru to use my HttpClientExtendedWithLogging class not the original class which doesn't seem to be possible currently due to the way the run method is implemented. In other words, I need to tell Gru to use my HttpClient builder, not the one coming with JDK.

@musketyr
Copy link
Collaborator

Ok, take a look at #104 if it solves your issue

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 a pull request may close this issue.

2 participants