From d70e48564a9a419fcc75a090dd5581e90009afda Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 7 Nov 2025 17:47:28 +0000 Subject: [PATCH 1/2] Fix: Rewrite Location headers in proxy The proxy was previously forwarding redirect responses from the target server to the client without modification. This caused the client to bypass the proxy and connect directly to the target server. This change modifies the SimpleProxyServlet to intercept redirect responses and rewrite the Location header to point back to the proxy server. This ensures that all traffic remains routed through the proxy. --- SimpleProxyServlet.java | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/SimpleProxyServlet.java b/SimpleProxyServlet.java index 6dae354..57b31eb 100644 --- a/SimpleProxyServlet.java +++ b/SimpleProxyServlet.java @@ -127,7 +127,11 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws String headerName = entry.getKey(); if (headerName != null && !headerName.equalsIgnoreCase("Transfer-Encoding")) { for (String value : entry.getValue()) { - resp.addHeader(headerName, value); + if (headerName.equalsIgnoreCase("Location") && (responseCode >= 300 && responseCode < 400)) { + resp.addHeader(headerName, rewriteUrl(value, req)); + } else { + resp.addHeader(headerName, value); + } } } } @@ -154,4 +158,33 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws } } + private String rewriteUrl(String locationHeader, HttpServletRequest request) { + if (locationHeader == null) { + return null; + } + + try { + URL originalUrl = new URL(locationHeader); + String proxyHost = request.getServerName(); + int proxyPort = request.getServerPort(); + String proxyScheme = request.getScheme(); + + // Use -1 for default port + if ((proxyScheme.equals("http") && proxyPort == 80) || (proxyScheme.equals("https") && proxyPort == 443)) { + proxyPort = -1; + } + + + // Build the rewritten URL using the proxy's host and port + URL rewrittenUrl = new URL(proxyScheme, proxyHost, proxyPort, originalUrl.getFile()); + log("Rewriting redirect Location header to: " + rewrittenUrl.toString()); + return rewrittenUrl.toString(); + + } catch (MalformedURLException e) { + // If the location is not a valid URL (e.g., a relative path), just return it as is + log("Location header is not a valid URL, passing through: " + locationHeader); + return locationHeader; + } + } + } From a2984168661b71705adca9bf1d259d9bf01b7df6 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 7 Nov 2025 20:17:11 +0000 Subject: [PATCH 2/2] Fix: Handle dynamic URLs in proxy The proxy was failing to handle dynamic URLs for 'apex/wwv_flow.ajax' because the 'contains' mapping type in web.xml was dropping query parameters. This has been changed to a 'prefix' mapping to correctly forward the entire URL, including dynamic parts. --- apex/WEB-INF/web.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apex/WEB-INF/web.xml b/apex/WEB-INF/web.xml index a772458..2f925ec 100644 --- a/apex/WEB-INF/web.xml +++ b/apex/WEB-INF/web.xml @@ -32,15 +32,15 @@ mapping.3.type - contains + prefix mapping.3.path - apex/wwv_flow.ajax? + /apex/wwv_flow.ajax mapping.3.url - ${baseUrl}/apex/wwv_flow.ajax? + ${baseUrl}/apex/wwv_flow.ajax mapping.4.type