From ffe5da4ba246cd9f1d345f486c3b73ab240046d2 Mon Sep 17 00:00:00 2001 From: mmelko Date: Mon, 29 Jan 2024 21:41:45 +0100 Subject: [PATCH] fix(ProxyServlet): Refactor how url being created when 300-303 status is received --- .../java/io/hawt/web/proxy/ProxyServlet.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/hawtio-system/src/main/java/io/hawt/web/proxy/ProxyServlet.java b/hawtio-system/src/main/java/io/hawt/web/proxy/ProxyServlet.java index 080d3119ca..6354453603 100644 --- a/hawtio-system/src/main/java/io/hawt/web/proxy/ProxyServlet.java +++ b/hawtio-system/src/main/java/io/hawt/web/proxy/ProxyServlet.java @@ -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; } @@ -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; }