malliaridis commented on PR #2778:
URL: https://github.com/apache/solr/pull/2778#issuecomment-2426569848

   @janhoy For some reason I am not surprised. I guess a `hostContext` that 
contains only `/` may be valid from the user's perspective, but we cannot 
handle it without additional workarounds and the current logic.
   
   I would prefer to use a URL builder which we can feed the path segments with 
and without leading and trailing slashes and it will take care of everything. 
Otherwise we would have to add just another workaround, like
   
   ```java
   if (hostContext.equals("/")) {
     hostContext = "";
   }
   ```
   
   right after the current workaround `if (hostContext.isBlank()) {...}`. Maybe 
it's time to reconsider the normalization logic?Concatenating URL paths should 
definitely not be done by simply appending the paths, as we cannot guarantee 
the presence / absence of slashes.
   
   _Using URL builders_
   I looked into the implementation of 
`org.apache.http.client.utils.URIBuilder` and `jakarta.ws.rs.core.UriBuilder` 
(both present right now) and only the jakarta implementation can take leading 
and trailing slashes into account, if used properly. This means that code like:
   
   ```java
   solrUpdateUrl = UriBuilder.fromUri(SolrCLI.normalizeSolrUrl(solrUrl, true, 
hostContext))
       .path(hostContext)
       .path(cli.getOptionValue("name")) // "testBasicRun"
       .path("/update")
       .path("/with/")
       .path("slashes/")
       .path("/again")
       .build();
   // generates 
http://127.0.0.1:52371/solr/testBasicRun/update/with/slashes/again
   
   ```
   would correctly generate the path.
   
   But using `UriBuilder#segment` which looks like a more suitable function 
would escape the slashes:
    ```java
   solrUpdateUrl = UriBuilder.fromUri(SolrCLI.normalizeSolrUrl(solrUrl, true, 
hostContext) + hostContext)
       .segment(cli.getOptionValue("name"), "/update", "/with/", "slashes/", 
"/again")
       .build();
   // generates 
http://127.0.0.1:52215/solr/testBasicRun/%2Fupdate/%2Fwith%2F/slashes%2F/%2Fagain
   ```
   
   Maybe we could use a more robust solution like that?


-- 
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: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to