Kong / unirest-java

Unirest in Java: Simplified, lightweight HTTP client library.
http://kong.github.io/unirest-java/
MIT License
2.58k stars 591 forks source link

Make method protected [ApacheClient.setOptions()] #417

Closed Pritesh-Mhatre closed 2 years ago

Pritesh-Mhatre commented 2 years ago

Is your feature request related to a problem? Please describe. I need to do a small modification in the HTTP client (need to use LaxRedirectStrategy). If the method kong.unirest.apache.ApacheClient.setOptions() is made protected, then it will be a lot easier as I can simply extend the class and override the method.

https://github.com/Kong/unirest-java/blob/07683eee893c73748d5b8cd549ab2cc4dc738565/unirest/src/main/java/kong/unirest/apache/ApacheClient.java#L81

Describe the solution you'd like Make the method protected.

ryber commented 2 years ago

I'm generally not a fan of allowing that kind of customization. It turns the internals of the class into a type of API, and it also will cause unexpected results if people forget to call super.

There are also additional things configured outside of this method. It was really only there to make things more readable for maintainers.

However I agree there should be a way to add additional configs when you aren't interested in building the entire client yourself and just want to tweek one little thing.

So I've introduced a Consumer in the builder that takes a ApacheClientBuilder. This is invoked AFTER Unirest has done all of it's own confgs. Which lets you either override or add settings:

Unirest.config().httpClient(ApacheClient.builder(c -> c.setRedirectStrategy(new LaxRedirectStrategy()));

This is available in Unirest 3.13.3

Pritesh-Mhatre commented 2 years ago

Thanks, appreciate your response. Your solution would surely make it easy to customize.

Beautiful product by the way....good luck!!!