Merged branch 'jetty-9.2.x' into 'master'.

This commit is contained in:
Simone Bordet 2015-06-05 12:34:47 +02:00
commit 87b1ae44f8
6 changed files with 267 additions and 164 deletions

View File

@ -1,5 +1,35 @@
jetty-9.3.0-SNAPSHOT
jetty-9.2.11.v20150529 - 29 May 2015
+ 461499 ConnectionPool may leak connections.
+ 463579 Add support for 308 status code.
+ 464292 Implement stream-based transformer for AsyncMiddleManServlet.
+ 464438 ClassFileTransformer support in
org.eclipse.jetty.webapp.WebAppClassLoader broken
+ 464740 DosFilter whiteList check improvement
+ 464869 PathResource.addPath allows absolute resolution.
+ 464989 AbstractSessionManager.removeEventListener() should remove
HttpSessionIdListener
+ 465053 Prevent gzip buffer overflow on complete
+ 465181 HttpParser parse full end chunk.
+ 465202 Forked Mojo does not extract war overlays/dependencies
+ 465359 Resource.newResource(String res, boolean useCache) does not use
useCache argument
+ 465360 URLResource.addPath should use _useCaches setting to create new
Resource
+ 465700 NullPointerException in ResourceHandler with welcome files
+ 465734 DosFilter whitelist bit pattern fix
+ 465747 Jetty is failing to process all HTTP OPTIONS requests.
+ 466329 Fixed local only TestFilter
+ 467276 NPE protection in SslContextFactory
+ 467603 Response 401 from server hangs client.
+ 467936 w Check HttpOutput aggregateSize is < bufferSize
+ 468008 Scanner ignores directory length
+ 468421 HttpClient#send fails with IllegalArgumentException on non-lowercase
schemes.
+ 468714 SelectorManager updateKey race without submit
+ 468747 XSS vulnerability in HttpSpiContextHandler
jetty-9.3.0.RC0 - 12 May 2015
+ 414479 Add WebSocketPingPongListener for those that want PING/PONG payload
data
@ -97,6 +127,16 @@ jetty-9.3.0.RC0 - 12 May 2015
+ 467043 WebSocketClient close codes on protocol violation reported as policy
violation
jetty-9.2.11.M0 - 25 March 2015
+ 454934 WebSocketClient / connectToServer can block indefinitely during
upgrade failure
+ 459273 Redundant license notices
+ 461499 ConnectionPool may leak connections.
+ 461919 Use osgi-friendly serviceloader mechanism for WebSocketServletFactory
+ 461941 JMX Remote host:port set from start properties
+ 462546 ShutdownMonitor should bind to jetty.host
+ 462616 Race between finishing a connect and timing it out.
jetty-9.3.0.M2 - 11 March 2015
+ 383207 Use BundleFileLocatorHelperFactory to obtain BundleFileLocatorHelper
+ 420944 Hot Deployment of WAR when Context XML exists doesn't trigger
@ -239,92 +279,6 @@ jetty-9.3.0.M2 - 11 March 2015
+ 461623 BufferUtil.writeTo does not update position consistently
+ 461643 HttpContent.advance() race.
jetty-9.3.0.M1 - 03 November 2014
+ 376365 "jetty.sh start" returns 0 on failure
+ 396569 'bin/jetty.sh stop' reports 'OK' even when jetty was not running
+ 396572 Starting jetty from cygwin is not working properly
+ 437303 Serving of static filenames with "unwise" characters causes 404 error
+ 440729 SSL requests often fail with EOFException or IllegalStateException.
+ 440925 NPE when using relative paths for --start-log-file
+ 442419 CrossOriginFilter javadoc says "exposeHeaders", but should be
"exposedHeaders"
+ 442942 Content sent with status 204 (No Content)
+ 443529 CrossOriginFilter does not accept wildcard for allowedHeaders
+ 443530 CrossOriginFilter does not set the Vary header
+ 443550 improved FileResource encoded alias checking
+ 444031 Ensure exceptions do not reduce threadpool below minimum
+ 444595 nosql/mongodb - Cleanup process/Refreshing does not respect encoding
of attribute keys
+ 444676 Goal jetty:deploy-war produces errors with version 9.2.3
+ 444722 Fixed order of setReuseAddress call
+ 444896 Overriding of web-default servlet mapping in web.xml not working with
quickstart
+ 445157 First redeployed servlet leaks WebAppContext
+ 445167 Allow configuration of dispatch after select.
+ 445239 Rename weld.mod to cdi.mod to be consistent with past module namings
+ 445258 STOP.WAIT is not really respected
+ 445374 Reevaluate org.eclipse.jetty.websocket.jsr356 enablement concepts
+ 445495 Improve Exception message when no jndi resource to bind for a name in
web.xml
+ 445542 Add SecuredRedirectHandler for embedded jetty use to redirect to
secure port/scheme
+ 445821 Error 400 should be logged with RequestLog
+ 445823 Moved RequestLog calling to HttpChannel
+ 445830 Support setting environment variables on forked jetty with
jetty:run-forked
+ 445979 jetty.sh fails to start when start-stop-daemon does not exist and the
user is not root
+ 446033 org.eclipse.jetty.websocket.server.WebSocketServerFactory not
available in OSGi
+ 446063 ALPN Fail SSL Handshake if no supported Application Protocols.
+ 446107 NullPointerException in ProxyServlet when extended by Servlet without
a package
+ 446425 Oracle Sql error on JettySessions table when this table do not exist
already
+ 446506 getAsyncContext ISE before startAsync on async dispatches
+ 446559 Avoid spin consuming extra data
+ 446563 Null HttpChannel.getCurrentHttpChannel() in
ServletHandler.doFilter().
+ 446564 Refactored RequestLog Mechanism
+ 446672 NPN Specification issue in the case no protocols are selected.
+ 446923 SharedBlockingCallback does not handle connector max idle time of
Long.MAX_VALUE; BlockerTimeoutException not serializable
+ 446944 ServletTester and HttpTester should be in
<classifier>tests</classifier>
+ 447216 putAll Properties in XmlConfiguration
+ 447381 Disable SSLv3 by default.
+ 447472 test harness for slow large writes
+ 447515 Remove GzipFilter
+ 447627 MultiPart file always created when "filename" set in
Content-Disposition
+ 447629 getPart()/getParts() fails on Multipart request if getParameter is
called in a filter first
+ 447746 HttpClient is always going to send User-Agent header even though I do
not want it to.
+ 447979 Refactor to make MetaData responsible for progressively ordering
web-inf jars
+ 448156 Fixed INACTIVE race in IteratingCallback
+ 448225 Removed unnecessary synchronize on initParser
+ 448675 Impossible to set own Threadpool when using jetty-maven-plugin
+ 448841 Clarified selectors==0 javadoc 448840 Clarified ServerConnector
javadoc 448839 Fixed javadoc typo in ServerConnector
+ 449001 Remove start.d directory from JETTY_HOME
+ 449003 WARNING: Cannot enable requested module [protonego-impl]: not a valid
module name
+ 449038 WebSocketUpgradeFilter must support async.
+ 449175 Removed extra space in NCSA log
+ 449372 Make jvmArgs of jetty:run-forked configurable from command line
jetty-9.2.11.M0 - 25 March 2015
+ 454934 WebSocketClient / connectToServer can block indefinitely during
upgrade failure
+ 459273 Redundant license notices
+ 461499 ConnectionPool may leak connections.
+ 461919 Use osgi-friendly serviceloader mechanism for WebSocketServletFactory
+ 461941 JMX Remote host:port set from start properties
+ 462546 ShutdownMonitor should bind to jetty.host
+ 462616 Race between finishing a connect and timing it out.
jetty-9.2.10.v20150310 - 10 March 2015
+ 445518 Provide different error callbacks to ProxyServlet.
+ 456521 ShutdownHandler should shut down more gracefully
@ -442,6 +396,82 @@ jetty-9.2.5.v20141112 - 12 November 2014
+ 450873 Disable tests that downcaste wrapped GzipFilterResponses
+ 450894 jetty.sh does not delete JETTY_STATE at start
jetty-9.3.0.M1 - 03 November 2014
+ 376365 "jetty.sh start" returns 0 on failure
+ 396569 'bin/jetty.sh stop' reports 'OK' even when jetty was not running
+ 396572 Starting jetty from cygwin is not working properly
+ 437303 Serving of static filenames with "unwise" characters causes 404 error
+ 440729 SSL requests often fail with EOFException or IllegalStateException.
+ 440925 NPE when using relative paths for --start-log-file
+ 442419 CrossOriginFilter javadoc says "exposeHeaders", but should be
"exposedHeaders"
+ 442942 Content sent with status 204 (No Content)
+ 443529 CrossOriginFilter does not accept wildcard for allowedHeaders
+ 443530 CrossOriginFilter does not set the Vary header
+ 443550 improved FileResource encoded alias checking
+ 444031 Ensure exceptions do not reduce threadpool below minimum
+ 444595 nosql/mongodb - Cleanup process/Refreshing does not respect encoding
of attribute keys
+ 444676 Goal jetty:deploy-war produces errors with version 9.2.3
+ 444722 Fixed order of setReuseAddress call
+ 444896 Overriding of web-default servlet mapping in web.xml not working with
quickstart
+ 445157 First redeployed servlet leaks WebAppContext
+ 445167 Allow configuration of dispatch after select.
+ 445239 Rename weld.mod to cdi.mod to be consistent with past module namings
+ 445258 STOP.WAIT is not really respected
+ 445374 Reevaluate org.eclipse.jetty.websocket.jsr356 enablement concepts
+ 445495 Improve Exception message when no jndi resource to bind for a name in
web.xml
+ 445542 Add SecuredRedirectHandler for embedded jetty use to redirect to
secure port/scheme
+ 445821 Error 400 should be logged with RequestLog
+ 445823 Moved RequestLog calling to HttpChannel
+ 445830 Support setting environment variables on forked jetty with
jetty:run-forked
+ 445979 jetty.sh fails to start when start-stop-daemon does not exist and the
user is not root
+ 446033 org.eclipse.jetty.websocket.server.WebSocketServerFactory not
available in OSGi
+ 446063 ALPN Fail SSL Handshake if no supported Application Protocols.
+ 446107 NullPointerException in ProxyServlet when extended by Servlet without
a package
+ 446425 Oracle Sql error on JettySessions table when this table do not exist
already
+ 446506 getAsyncContext ISE before startAsync on async dispatches
+ 446559 Avoid spin consuming extra data
+ 446563 Null HttpChannel.getCurrentHttpChannel() in
ServletHandler.doFilter().
+ 446564 Refactored RequestLog Mechanism
+ 446672 NPN Specification issue in the case no protocols are selected.
+ 446923 SharedBlockingCallback does not handle connector max idle time of
Long.MAX_VALUE; BlockerTimeoutException not serializable
+ 446944 ServletTester and HttpTester should be in
<classifier>tests</classifier>
+ 447216 putAll Properties in XmlConfiguration
+ 447381 Disable SSLv3 by default.
+ 447472 test harness for slow large writes
+ 447515 Remove GzipFilter
+ 447627 MultiPart file always created when "filename" set in
Content-Disposition
+ 447629 getPart()/getParts() fails on Multipart request if getParameter is
called in a filter first
+ 447746 HttpClient is always going to send User-Agent header even though I do
not want it to.
+ 447979 Refactor to make MetaData responsible for progressively ordering
web-inf jars
+ 448156 Fixed INACTIVE race in IteratingCallback
+ 448225 Removed unnecessary synchronize on initParser
+ 448675 Impossible to set own Threadpool when using jetty-maven-plugin
+ 448841 Clarified selectors==0 javadoc 448840 Clarified ServerConnector
javadoc 448839 Fixed javadoc typo in ServerConnector
+ 449001 Remove start.d directory from JETTY_HOME
+ 449003 WARNING: Cannot enable requested module [protonego-impl]: not a valid
module name
+ 449038 WebSocketUpgradeFilter must support async.
+ 449175 Removed extra space in NCSA log
+ 449372 Make jvmArgs of jetty:run-forked configurable from command line
jetty-9.2.4.v20141103 - 03 November 2014
+ 376365 "jetty.sh start" returns 0 on failure
+ 396569 'bin/jetty.sh stop' reports 'OK' even when jetty was not running
@ -932,7 +962,7 @@ jetty-9.1.2.v20140210 - 10 February 2014
+ 423421 remove org.slf4j and org.ow2.asm from jetty-all artifact
+ 424171 Old javax.activation jar interferes with email sending
+ 424562 JDBCSessionManager.setNodeIdInSessionId(true) does not work
+ 425275
+ 425275
org.eclipse.jetty.osgi.annotations.AnnotationConfiguration.BundleParserTask.getStatistic()
returns null when debug is enabled.
+ 425638 Fixed monitor module/xml typos
@ -1235,7 +1265,7 @@ jetty-9.0.6.v20130930 - 30 September 2013
in the value
+ 415192 <jsp-file> maps to JspPropertyGroupServlet instead of JspServlet
+ 415194 Deployer gives management of context to context collection
+ 415302
+ 415302
+ 415330 Avoid multiple callbacks at EOF
+ 415401 Add initalizeDefaults call to SpringConfigurationProcessor
+ 415548 migrate ProxyHTTPToSPDYTest to use HttpClient to avoid intermittent
@ -1375,7 +1405,7 @@ jetty-9.1.0.M0 - 16 September 2013
+ 415131 Avoid autoboxing on debug
+ 415192 <jsp-file> maps to JspPropertyGroupServlet instead of JspServlet
+ 415194 Deployer gives management of context to context collection
+ 415302
+ 415302
+ 415314 Jetty should not commit response on output if <
Response.setBufferSize() bytes are written
+ 415330 Avoid multiple callbacks at EOF

View File

@ -18,6 +18,28 @@
package org.eclipse.jetty.proxy;
import java.io.IOException;
import java.net.InetAddress;
import java.net.URI;
import java.net.UnknownHostException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeoutException;
import javax.servlet.AsyncContext;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.UnavailableException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.api.Response;
@ -29,21 +51,32 @@ import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import javax.servlet.AsyncContext;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.UnavailableException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.InetAddress;
import java.net.URI;
import java.net.UnknownHostException;
import java.util.*;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeoutException;
/**
* <p>Abstract base class for proxy servlets.</p>
* <p>Forwards requests to another server either as a standard web reverse
* proxy or as a transparent reverse proxy (as defined by RFC 7230).</p>
* <p>To facilitate JMX monitoring, the {@link HttpClient} instance is set
* as ServletContext attribute, prefixed with this servlet's name and
* exposed by the mechanism provided by
* {@link ServletContext#setAttribute(String, Object)}.</p>
* <p>The following init parameters may be used to configure the servlet:</p>
* <ul>
* <li>preserveHost - the host header specified by the client is forwarded to the server</li>
* <li>hostHeader - forces the host header to a particular value</li>
* <li>viaHost - the name to use in the Via header: Via: http/1.1 &lt;viaHost&gt;</li>
* <li>whiteList - comma-separated list of allowed proxy hosts</li>
* <li>blackList - comma-separated list of forbidden proxy hosts</li>
* </ul>
* <p>In addition, see {@link #createHttpClient()} for init parameters
* used to configure the {@link HttpClient} instance.</p>
* <p>NOTE: By default the Host header sent to the server by this proxy
* servlet is the server's host name. However, this breaks redirects.
* Set {@code preserveHost} to {@code true} to make redirects working,
* although this may break server's virtual host selection.</p>
* <p>The default behavior of not preserving the Host header mimics
* the default behavior of Apache httpd and Nginx, which both have
* a way to be configured to preserve the Host header.</p>
*/
public abstract class AbstractProxyServlet extends HttpServlet
{
protected static final Set<String> HOP_HEADERS;
@ -65,6 +98,7 @@ public abstract class AbstractProxyServlet extends HttpServlet
private final Set<String> _whiteList = new HashSet<>();
private final Set<String> _blackList = new HashSet<>();
protected Logger _log;
private boolean _preserveHost;
private String _hostHeader;
private String _viaHost;
private HttpClient _client;
@ -77,6 +111,8 @@ public abstract class AbstractProxyServlet extends HttpServlet
ServletConfig config = getServletConfig();
_preserveHost = Boolean.parseBoolean(config.getInitParameter("preserveHost"));
_hostHeader = config.getInitParameter("hostHeader");
_viaHost = config.getInitParameter("viaHost");
@ -175,9 +211,8 @@ public abstract class AbstractProxyServlet extends HttpServlet
}
/**
* Creates a {@link HttpClient} instance, configured with init parameters of this servlet.
* <p>
* The init parameters used to configure the {@link HttpClient} instance are:
* <p>Creates a {@link HttpClient} instance, configured with init parameters of this servlet.</p>
* <p>The init parameters used to configure the {@link HttpClient} instance are:</p>
* <table>
* <caption>Init Parameters</caption>
* <thead>
@ -403,7 +438,7 @@ public abstract class AbstractProxyServlet extends HttpServlet
String headerName = headerNames.nextElement();
String lowerHeaderName = headerName.toLowerCase(Locale.ENGLISH);
if (HttpHeader.HOST.is(headerName))
if (HttpHeader.HOST.is(headerName) && !_preserveHost)
continue;
// Remove hop-by-hop headers.

View File

@ -18,6 +18,27 @@
package org.eclipse.jetty.proxy;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPOutputStream;
import javax.servlet.AsyncContext;
import javax.servlet.ReadListener;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.client.ContentDecoder;
import org.eclipse.jetty.client.GZIPContentDecoder;
import org.eclipse.jetty.client.api.ContentProvider;
@ -34,21 +55,15 @@ import org.eclipse.jetty.util.CountingCallback;
import org.eclipse.jetty.util.IteratingCallback;
import org.eclipse.jetty.util.component.Destroyable;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPOutputStream;
@SuppressWarnings("serial")
/**
* <p>Servlet 3.1 asynchronous proxy servlet with capability
* to intercept and modify request/response content.</p>
* <p>Both the request processing and the I/O are asynchronous.</p>
*
* @see ProxyServlet
* @see AsyncProxyServlet
* @see ConnectHandler
*/
public class AsyncMiddleManServlet extends AbstractProxyServlet
{
private static final String CLIENT_TRANSFORMER = AsyncMiddleManServlet.class.getName() + ".clientTransformer";
@ -190,6 +205,8 @@ public class AsyncMiddleManServlet extends AbstractProxyServlet
/**
* <p>Convenience extension of {@link AsyncMiddleManServlet} that offers transparent proxy functionalities.</p>
*
* @see TransparentDelegate
*/
public static class Transparent extends ProxyServlet
{
@ -272,7 +289,7 @@ public class AsyncMiddleManServlet extends AbstractProxyServlet
if (_log.isDebugEnabled())
_log.debug("{} asynchronous read {} bytes on {}", getRequestId(clientRequest), read, input);
if (read<0)
if (read < 0)
return Action.SUCCEEDED;
if (contentLength > 0 && read > 0)

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.proxy;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.WritePendingException;
import javax.servlet.ReadListener;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
@ -38,9 +39,12 @@ import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.IteratingCallback;
/**
* <p>Proxy servlet based on Servlet 3.1 async I/O.</p>
* <p>Servlet 3.1 asynchronous proxy servlet.</p>
* <p>Both the request processing and the I/O are asynchronous.</p>
*
* @see ProxyServlet
* @see AsyncMiddleManServlet
* @see ConnectHandler
*/
public class AsyncProxyServlet extends ProxyServlet
{
@ -101,6 +105,8 @@ public class AsyncProxyServlet extends ProxyServlet
/**
* <p>Convenience extension of {@link AsyncProxyServlet} that offers transparent proxy functionalities.</p>
*
* @see TransparentDelegate
*/
public static class Transparent extends AsyncProxyServlet
{

View File

@ -22,14 +22,13 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.concurrent.TimeUnit;
import javax.servlet.AsyncContext;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentProvider;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.api.Response;
@ -39,22 +38,11 @@ import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.util.Callback;
/**
* <p>Proxy servlet based on Servlet 3.0 asynchronous request/response.</p>
* <p>Forwards requests to another server either as a standard web reverse proxy
* (as defined by RFC2616) or as a transparent reverse proxy.</p>
* <p>To facilitate JMX monitoring, the {@link HttpClient} instance is set as
* context attribute, prefixed with the servlet's name and exposed by the
* mechanism provided by {@link ServletContext#setAttribute(String, Object)}.</p>
* <p>The following init parameters may be used to configure the servlet:</p>
* <ul>
* <li>hostHeader - forces the host header to a particular value</li>
* <li>viaHost - the name to use in the Via header: Via: http/1.1 &lt;viaHost&gt;</li>
* <li>whiteList - comma-separated list of allowed proxy hosts</li>
* <li>blackList - comma-separated list of forbidden proxy hosts</li>
* </ul>
* <p>In addition, see {@link #createHttpClient()} for init parameters used to configure
* the {@link HttpClient} instance.</p>
* <p>Servlet 3.0 asynchronous proxy servlet.</p>
* <p>The request processing is asynchronous, but the I/O is blocking.</p>
*
* @see AsyncProxyServlet
* @see AsyncMiddleManServlet
* @see ConnectHandler
*/
public class ProxyServlet extends AbstractProxyServlet
@ -127,6 +115,8 @@ public class ProxyServlet extends AbstractProxyServlet
/**
* <p>Convenience extension of {@link ProxyServlet} that offers transparent proxy functionalities.</p>
*
* @see TransparentDelegate
*/
public static class Transparent extends ProxyServlet
{

View File

@ -19,6 +19,8 @@
package org.eclipse.jetty.proxy;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@ -43,13 +45,27 @@ public class ReverseProxyTest
{
@Rule
public final TestTracker tracker = new TestTracker();
private HttpClient client;
private Server proxy;
private ServerConnector proxyConnector;
private Server server;
private ServerConnector serverConnector;
private Server proxy;
private ServerConnector proxyConnector;
private HttpClient client;
private void startProxy() throws Exception
private void startServer(HttpServlet servlet) throws Exception
{
server = new Server();
serverConnector = new ServerConnector(server);
server.addConnector(serverConnector);
ServletContextHandler appCtx = new ServletContextHandler(server, "/", true, false);
ServletHolder appServletHolder = new ServletHolder(servlet);
appCtx.addServlet(appServletHolder, "/*");
server.start();
}
private void startProxy(Map<String, String> params) throws Exception
{
proxy = new Server();
@ -66,7 +82,7 @@ public class ReverseProxyTest
protected String rewriteTarget(HttpServletRequest clientRequest)
{
StringBuilder builder = new StringBuilder();
builder.append(clientRequest.getScheme()).append("://localhost:");
builder.append(clientRequest.getScheme()).append("://127.0.0.1:");
builder.append(serverConnector.getLocalPort());
builder.append(clientRequest.getRequestURI());
String query = clientRequest.getQueryString();
@ -75,25 +91,14 @@ public class ReverseProxyTest
return builder.toString();
}
});
if (params != null)
proxyServletHolder.setInitParameters(params);
proxyContext.addServlet(proxyServletHolder, "/*");
proxy.start();
}
private void startServer(HttpServlet servlet) throws Exception
{
server = new Server();
serverConnector = new ServerConnector(server);
server.addConnector(serverConnector);
ServletContextHandler appCtx = new ServletContextHandler(server, "/", true, false);
ServletHolder appServletHolder = new ServletHolder(servlet);
appCtx.addServlet(appServletHolder, "/*");
server.start();
}
private void startClient() throws Exception
{
client = new HttpClient();
@ -109,17 +114,37 @@ public class ReverseProxyTest
}
@Test
public void testClientHostHeaderUpdatedWhenSentToServer() throws Exception
public void testHostHeaderUpdatedWhenSentToServer() throws Exception
{
startServer(new HttpServlet()
{
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
Assert.assertEquals(request.getServerPort(), serverConnector.getLocalPort());
Assert.assertEquals("127.0.0.1", request.getServerName());
Assert.assertEquals(serverConnector.getLocalPort(), request.getServerPort());
}
});
startProxy();
startProxy(null);
startClient();
ContentResponse response = client.newRequest("localhost", proxyConnector.getLocalPort()).send();
Assert.assertEquals(200, response.getStatus());
}
@Test
public void testHostHeaderPreserved() throws Exception
{
startServer(new HttpServlet()
{
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
Assert.assertEquals("localhost", request.getServerName());
Assert.assertEquals(proxyConnector.getLocalPort(), request.getServerPort());
}
});
startProxy(new HashMap<String, String>() {{ put("preserveHost", "true"); }});
startClient();
ContentResponse response = client.newRequest("localhost", proxyConnector.getLocalPort()).send();