Merged branch 'jetty-9.2.x' into 'master'.
This commit is contained in:
commit
67f155bcf9
|
@ -705,12 +705,22 @@ public abstract class AbstractProxyServlet extends HttpServlet
|
||||||
if (_proxyTo.endsWith("/"))
|
if (_proxyTo.endsWith("/"))
|
||||||
uri.setLength(uri.length() - 1);
|
uri.setLength(uri.length() - 1);
|
||||||
String rest = path.substring(_prefix.length());
|
String rest = path.substring(_prefix.length());
|
||||||
|
if (!rest.isEmpty())
|
||||||
|
{
|
||||||
if (!rest.startsWith("/"))
|
if (!rest.startsWith("/"))
|
||||||
uri.append("/");
|
uri.append("/");
|
||||||
uri.append(rest);
|
uri.append(rest);
|
||||||
|
}
|
||||||
|
|
||||||
String query = request.getQueryString();
|
String query = request.getQueryString();
|
||||||
if (query != null)
|
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.append("?").append(query);
|
||||||
|
}
|
||||||
URI rewrittenURI = URI.create(uri.toString()).normalize();
|
URI rewrittenURI = URI.create(uri.toString()).normalize();
|
||||||
|
|
||||||
if (!proxyServlet.validateDestination(rewrittenURI.getHost(), rewrittenURI.getPort()))
|
if (!proxyServlet.validateDestination(rewrittenURI.getHost(), rewrittenURI.getPort()))
|
||||||
|
|
|
@ -141,7 +141,7 @@ public class ProxyServletTest
|
||||||
|
|
||||||
private void startProxy() throws Exception
|
private void startProxy() throws Exception
|
||||||
{
|
{
|
||||||
startProxy(new HashMap<String, String>());
|
startProxy(new HashMap<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startProxy(Map<String, String> initParams) throws Exception
|
private void startProxy(Map<String, String> initParams) throws Exception
|
||||||
|
@ -651,7 +651,29 @@ public class ProxyServletTest
|
||||||
@Test
|
@Test
|
||||||
public void testTransparentProxyWithQuery() throws Exception
|
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";
|
final String query = "a=1&b=2";
|
||||||
startServer(new HttpServlet()
|
startServer(new HttpServlet()
|
||||||
{
|
{
|
||||||
|
@ -661,7 +683,10 @@ public class ProxyServletTest
|
||||||
if (req.getHeader("Via") != null)
|
if (req.getHeader("Via") != null)
|
||||||
resp.addHeader(PROXIED_HEADER, "true");
|
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()))
|
if (query.equals(req.getQueryString()))
|
||||||
{
|
{
|
||||||
|
@ -672,8 +697,7 @@ public class ProxyServletTest
|
||||||
resp.setStatus(404);
|
resp.setStatus(404);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
String proxyTo = "http://localhost:" + serverConnector.getLocalPort();
|
String proxyTo = "http://localhost:" + serverConnector.getLocalPort() + proxyToContext;
|
||||||
String prefix = "/proxy";
|
|
||||||
proxyServlet = new ProxyServlet.Transparent();
|
proxyServlet = new ProxyServlet.Transparent();
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
params.put("proxyTo", proxyTo);
|
params.put("proxyTo", proxyTo);
|
||||||
|
|
Loading…
Reference in New Issue