Implemented the PROXY protocol

Added XML templates
This commit is contained in:
Greg Wilkins 2014-11-14 12:04:57 +11:00
parent 5b60e0c98d
commit ce4af5a8b9
4 changed files with 37 additions and 4 deletions

View File

@ -26,6 +26,10 @@
<Arg name="selectors" type="int"><Property name="http.selectors" default="-1"/></Arg>
<Arg name="factories">
<Array type="org.eclipse.jetty.server.ConnectionFactory">
<!-- uncomment to support proxy protocol
<Item>
<New class="org.eclipse.jetty.server.ProxyConnectionFactory"/>
</Item>-->
<Item>
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
<Arg name="config"><Ref refid="httpConfig" /></Arg>

View File

@ -19,6 +19,10 @@
<Arg name="selectors" type="int"><Property name="ssl.selectors" default="-1"/></Arg>
<Arg name="factories">
<Array type="org.eclipse.jetty.server.ConnectionFactory">
<!-- uncomment to support proxy protocol
<Item>
<New class="org.eclipse.jetty.server.ProxyConnectionFactory"/>
</Item>-->
</Array>
</Arg>

View File

@ -23,6 +23,7 @@ import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ReadPendingException;
import java.nio.channels.WritePendingException;
import java.util.Iterator;
import org.eclipse.jetty.io.AbstractConnection;
import org.eclipse.jetty.io.Connection;
@ -44,17 +45,41 @@ public class ProxyConnectionFactory extends AbstractConnectionFactory
{
private static final Logger LOG = Log.getLogger(ProxyConnectionFactory.class);
private final String _next;
/* ------------------------------------------------------------ */
/** Proxy Connection Factory that uses the next ConnectionFactory
* on the connector as the next protocol
*/
public ProxyConnectionFactory()
{
super("proxy");
_next=null;
}
public ProxyConnectionFactory(String nextProtocol)
{
super("haproxy");
super("proxy");
_next=nextProtocol;
}
@Override
public Connection newConnection(Connector connector, EndPoint endp)
{
return new ProxyConnection(endp,connector,_next);
String next=_next;
if (next==null)
{
for (Iterator<String> i = connector.getProtocols().iterator();i.hasNext();)
{
String p=i.next();
if (getProtocol().equalsIgnoreCase(p))
{
next=i.next();
break;
}
}
}
return new ProxyConnection(endp,connector,next);
}
public static class ProxyConnection extends AbstractConnection

View File

@ -43,7 +43,7 @@ public class ProxyConnectionTest
http.getHttpConfiguration().setRequestHeaderSize(1024);
http.getHttpConfiguration().setResponseHeaderSize(1024);
ProxyConnectionFactory proxy = new ProxyConnectionFactory(http.getProtocol());
ProxyConnectionFactory proxy = new ProxyConnectionFactory();
_connector = new LocalConnector(_server,null,null,null,1,proxy,http);
_connector.setIdleTimeout(1000);