code: protected static URL normalizeToEndWithSlash(URL url) {
          if(url.getPath().endsWith("/"))
              return url;
  
          // normalize
          String q = url.getQuery();
          q = q!=null?('?'+q):"";
          try {
              return new URL(url,url.getPath()+'/'+q);
          } catch (MalformedURLException e) {
              // impossible
              throw new Error(e);
          }
      }
docs: Normalize the URL so that it ends with '/'.
  <p>
  An attention is paid to preserve the query parameters in URL if any.