iamsanjay commented on PR #2689: URL: https://github.com/apache/solr/pull/2689#issuecomment-2374579550
> Wdyt about saving `getDefaultHttpClient()` take in a baseUrl, so that the returned instance can take advantage of all SolrClient methods "out of the box"? > > (Also - am I missing some existing discussion on this, maybe in 'resolved' GH comments? The [comment here](https://github.com/apache/solr/pull/2689#issuecomment-2329584805) gives me the impression that this has already come up and you've put some thought into it, but I'm having trouble digging up that context...) Currently, there are two known ways to set the base path URL: 1. SolrRequest.setBasePath 2. Recreate Http2SolrClient with the existing HttpClient and pass the base path URL. **Issues with the second approach:** Initially, we encountered authentication issues when recreating Http2SolrClient because the new instance was missing the appropriate listeners from the old client. This issue has been addressed in version 9.7, where recreating Http2SolrClient now also copies listeners along with properties like IdleTimeout, connectionTimeout, and others. The second issue was avoiding unnecessary object creation. Also, if someone recreates it, they are responsible for closing the instance. Therefore, recreating `Http2SolrClient` just for the base URL is not recommended. However, since we've deprecated the first approach, I now favor the idea that when users need to set the base path, they should recreate Http2SolrClient and use a `try-with-resources` block to ensure proper closure. ``` try(Http2SolrClient solrClient = new Http2SolrClient.Builder(baseLeaderURL).build()) { // code goes here } ``` Now to answer your question: Should this new method take a URL? Well, if we start taking a URL, we might need to recreate Http2SolrClient, for which the caller would then be responsible for closing. We could add an option where, if the user passes null, we don't create a new client and just return the existing Http2SolrClient. But that would introduce two responsibilities for this method — an anti-pattern. Instead, I would simply return the existing Http2SolrClient and let the user recreate it and set the base leader path in their own context, handling its lifecycle. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
