Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimone Bordet2015-07-28 14:48:54 +0000
committerSimone Bordet2015-07-28 14:48:54 +0000
commit67f155bcf90458f1467e780763f987c532e5cdb8 (patch)
tree1ef07e490e5bf4128ffdc577a0a46c1e7d99113a
parent25ed10d205619dd7b7fbf7cd9a3f37281adff38b (diff)
parent837d1a74bb7d694220644a2539c4440ce55462cf (diff)
downloadorg.eclipse.jetty.project-67f155bcf90458f1467e780763f987c532e5cdb8.tar.gz
org.eclipse.jetty.project-67f155bcf90458f1467e780763f987c532e5cdb8.tar.xz
org.eclipse.jetty.project-67f155bcf90458f1467e780763f987c532e5cdb8.zip
Merged branch 'jetty-9.2.x' into 'master'.
-rw-r--r--jetty-proxy/src/main/java/org/eclipse/jetty/proxy/AbstractProxyServlet.java16
-rw-r--r--jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletTest.java36
2 files changed, 43 insertions, 9 deletions
diff --git a/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/AbstractProxyServlet.java b/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/AbstractProxyServlet.java
index 0bdd0be450..bd2f0cb590 100644
--- a/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/AbstractProxyServlet.java
+++ b/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/AbstractProxyServlet.java
@@ -705,12 +705,22 @@ public abstract class AbstractProxyServlet extends HttpServlet
if (_proxyTo.endsWith("/"))
uri.setLength(uri.length() - 1);
String rest = path.substring(_prefix.length());
- if (!rest.startsWith("/"))
- uri.append("/");
- uri.append(rest);
+ if (!rest.isEmpty())
+ {
+ if (!rest.startsWith("/"))
+ uri.append("/");
+ uri.append(rest);
+ }
+
String query = request.getQueryString();
if (query != null)
+ {
+ // Is there at least one path segment ?
+ String separator = "://";
+ if (uri.indexOf("/", uri.indexOf(separator) + separator.length()) < 0)
+ uri.append("/");
uri.append("?").append(query);
+ }
URI rewrittenURI = URI.create(uri.toString()).normalize();
if (!proxyServlet.validateDestination(rewrittenURI.getHost(), rewrittenURI.getPort()))
diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletTest.java
index d3d4eb3ebb..1f96b48a51 100644
--- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletTest.java
+++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletTest.java
@@ -141,7 +141,7 @@ public class ProxyServletTest
private void startProxy() throws Exception
{
- startProxy(new HashMap<String, String>());
+ startProxy(new HashMap<>());
}
private void startProxy(Map<String, String> initParams) throws Exception
@@ -651,7 +651,29 @@ public class ProxyServletTest
@Test
public void testTransparentProxyWithQuery() throws Exception
{
- final String target = "/test";
+ testTransparentProxyWithQuery("/foo", "/proxy", "/test");
+ }
+
+ @Test
+ public void testTransparentProxyEmptyContextWithQuery() throws Exception
+ {
+ testTransparentProxyWithQuery("", "/proxy", "/test");
+ }
+
+ @Test
+ public void testTransparentProxyEmptyTargetWithQuery() throws Exception
+ {
+ testTransparentProxyWithQuery("/bar", "/proxy", "");
+ }
+
+ @Test
+ public void testTransparentProxyEmptyContextEmptyTargetWithQuery() throws Exception
+ {
+ testTransparentProxyWithQuery("", "/proxy", "");
+ }
+
+ private void testTransparentProxyWithQuery(String proxyToContext, String prefix, String target) throws Exception
+ {
final String query = "a=1&b=2";
startServer(new HttpServlet()
{
@@ -661,7 +683,10 @@ public class ProxyServletTest
if (req.getHeader("Via") != null)
resp.addHeader(PROXIED_HEADER, "true");
- if (target.equals(req.getRequestURI()))
+ String expectedURI = proxyToContext + target;
+ if (expectedURI.isEmpty())
+ expectedURI = "/";
+ if (expectedURI.equals(req.getRequestURI()))
{
if (query.equals(req.getQueryString()))
{
@@ -672,8 +697,7 @@ public class ProxyServletTest
resp.setStatus(404);
}
});
- String proxyTo = "http://localhost:" + serverConnector.getLocalPort();
- String prefix = "/proxy";
+ String proxyTo = "http://localhost:" + serverConnector.getLocalPort() + proxyToContext;
proxyServlet = new ProxyServlet.Transparent();
Map<String, String> params = new HashMap<>();
params.put("proxyTo", proxyTo);
@@ -689,7 +713,7 @@ public class ProxyServletTest
Assert.assertEquals(200, response.getStatus());
Assert.assertTrue(response.getHeaders().containsKey(PROXIED_HEADER));
}
-
+
@Test
public void testTransparentProxyWithQueryWithSpaces() throws Exception
{

Back to the top