Skip to content

Commit

Permalink
fix(ProxyServlet): Refactor how url being created when 300-303 status…
Browse files Browse the repository at this point in the history
… is received
  • Loading branch information
mmelko authored and tadayosi committed Jan 30, 2024
1 parent d6ed1cb commit ffe5da4
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions hawtio-system/src/main/java/io/hawt/web/proxy/ProxyServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ protected boolean doResponseRedirectOrNotModifiedLogic(
+ " but no " + HttpHeaders.LOCATION + " header was found in the response");
}

String locStr = rewriteUrlFromResponse(servletRequest,locationHeader.getValue(), Strings.sanitize(targetUriObj.toString()));
String locStr = rewriteUrlFromResponse(servletRequest,locationHeader.getValue(), targetUriObj.toString());
servletResponse.sendRedirect(locStr);
return true;
}
Expand Down Expand Up @@ -452,14 +452,15 @@ protected void copyResponseEntity(HttpResponse proxyResponse, HttpServletRespons
*/
protected String rewriteUrlFromResponse(HttpServletRequest servletRequest, String theUrl, String targetUri) {
//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());
String curUrl = String.format("%s://%s:%s%s%s", servletRequest.getScheme(),
servletRequest.getServerName(),
servletRequest.getServerPort(),
servletRequest.getContextPath(),
servletRequest.getServletPath());

theUrl = curUrl + theUrl.substring(targetUri.length() - 1);
}
return theUrl;
}
Expand Down

0 comments on commit ffe5da4

Please sign in to comment.