code: protected String rewriteUrlFromResponse(HttpServletRequest servletRequest, String theUrl)
     {
        /*
         * TODO document example paths
         */
        if (theUrl.startsWith(targetUri))
        {
           String curUrl = servletRequest.getRequestURL().toString();// no query
           String pathInfo = servletRequest.getPathInfo();
           if (pathInfo != null)
           {
              assert curUrl.endsWith(pathInfo);
              curUrl = curUrl.substring(0, curUrl.length() - pathInfo.length());// take pathInfo off
           }
           theUrl = curUrl + theUrl.substring(targetUri.length());
        }
        return theUrl;
     }
docs: For a redirect response from the target server, this translates {@code theUrl} to redirect to and translates it to
  one the original client can use.