AsyncMiddleManServlet.Transparent class wrongly extends ProxyServlet
`AsyncMiddleManServlet.Transparent` class should extend `AsyncMiddleManServlet` so the consumers can override the `newServerResponseContentTransformer` & `newServerResponseContentTransformer` to provide their own ContentTransformer. The way it is structured right now makes it impossible to use `AsyncMiddleManServlet.Transparent` servlet as a middle man servlet. Signed-off-by: Assim Deodia <assim.deodia@gmail.com>
This commit is contained in:
parent
525579a395
commit
eeeffed73a
|
@ -695,11 +695,11 @@ public abstract class AbstractProxyServlet extends HttpServlet
|
|||
*/
|
||||
protected static class TransparentDelegate
|
||||
{
|
||||
private final ProxyServlet proxyServlet;
|
||||
private final AbstractProxyServlet proxyServlet;
|
||||
private String _proxyTo;
|
||||
private String _prefix;
|
||||
|
||||
protected TransparentDelegate(ProxyServlet proxyServlet)
|
||||
protected TransparentDelegate(AbstractProxyServlet proxyServlet)
|
||||
{
|
||||
this.proxyServlet = proxyServlet;
|
||||
}
|
||||
|
|
|
@ -234,7 +234,7 @@ public class AsyncMiddleManServlet extends AbstractProxyServlet
|
|||
*
|
||||
* @see org.eclipse.jetty.proxy.AbstractProxyServlet.TransparentDelegate
|
||||
*/
|
||||
public static class Transparent extends ProxyServlet
|
||||
public static class Transparent extends AsyncMiddleManServlet
|
||||
{
|
||||
private final TransparentDelegate delegate = new TransparentDelegate(this);
|
||||
|
||||
|
|
|
@ -89,6 +89,8 @@ import org.junit.Test;
|
|||
public class AsyncMiddleManServletTest
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(AsyncMiddleManServletTest.class);
|
||||
private static final String PROXIED_HEADER = "X-Proxied";
|
||||
|
||||
@Rule
|
||||
public final TestTracker tracker = new TestTracker();
|
||||
private HttpClient client;
|
||||
|
@ -1483,6 +1485,41 @@ public class AsyncMiddleManServletTest
|
|||
Assert.assertEquals(chunk1.capacity() + chunk2.capacity(), response.getContent().length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransparentProxyWithIdentityContentTransformer() throws Exception
|
||||
{
|
||||
final String target = "/test";
|
||||
startServer(new HttpServlet()
|
||||
{
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
|
||||
{
|
||||
if (req.getHeader("Via") != null)
|
||||
resp.addHeader(PROXIED_HEADER, "true");
|
||||
resp.setStatus(target.equals(req.getRequestURI()) ? 200 : 404);
|
||||
}
|
||||
});
|
||||
final String proxyTo = "http://localhost:" + serverConnector.getLocalPort();
|
||||
AsyncMiddleManServlet proxyServlet = new AsyncMiddleManServlet.Transparent() {
|
||||
@Override
|
||||
protected ContentTransformer newServerResponseContentTransformer(HttpServletRequest clientRequest, HttpServletResponse proxyResponse, Response serverResponse) {
|
||||
return ContentTransformer.IDENTITY;
|
||||
}
|
||||
};
|
||||
Map<String, String> initParams = new HashMap<>();
|
||||
initParams.put("proxyTo", proxyTo);
|
||||
startProxy(proxyServlet, initParams);
|
||||
startClient();
|
||||
|
||||
// Make the request to the proxy, it should transparently forward to the server
|
||||
ContentResponse response = client.newRequest("localhost", proxyConnector.getLocalPort())
|
||||
.path(target)
|
||||
.timeout(5, TimeUnit.SECONDS)
|
||||
.send();
|
||||
Assert.assertEquals(200, response.getStatus());
|
||||
Assert.assertTrue(response.getHeaders().containsKey(PROXIED_HEADER));
|
||||
}
|
||||
|
||||
private Path prepareTargetTestsDir() throws IOException
|
||||
{
|
||||
final Path targetTestsDir = MavenTestingUtils.getTargetTestingDir().toPath();
|
||||
|
|
Loading…
Reference in New Issue