Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2014-11-13 20:04:57 -0500
committerGreg Wilkins2014-11-13 20:04:57 -0500
commitce4af5a8b992863e7e372cd0b89af3baed6c17d6 (patch)
tree9e9cf7a3c8097f78c785089de4a64cecee09dea5
parent5b60e0c98d5aa0643ad0684c42d9a09cc9827b6e (diff)
downloadorg.eclipse.jetty.project-ce4af5a8b992863e7e372cd0b89af3baed6c17d6.tar.gz
org.eclipse.jetty.project-ce4af5a8b992863e7e372cd0b89af3baed6c17d6.tar.xz
org.eclipse.jetty.project-ce4af5a8b992863e7e372cd0b89af3baed6c17d6.zip
Implemented the PROXY protocol
Added XML templates
-rw-r--r--jetty-server/src/main/config/etc/jetty-http.xml4
-rw-r--r--jetty-server/src/main/config/etc/jetty-ssl.xml4
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/ProxyConnectionFactory.java31
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/ProxyConnectionTest.java2
4 files changed, 37 insertions, 4 deletions
diff --git a/jetty-server/src/main/config/etc/jetty-http.xml b/jetty-server/src/main/config/etc/jetty-http.xml
index 1459ba8645..8456a14d4b 100644
--- a/jetty-server/src/main/config/etc/jetty-http.xml
+++ b/jetty-server/src/main/config/etc/jetty-http.xml
@@ -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>
diff --git a/jetty-server/src/main/config/etc/jetty-ssl.xml b/jetty-server/src/main/config/etc/jetty-ssl.xml
index dcb8506d2a..1fe331f256 100644
--- a/jetty-server/src/main/config/etc/jetty-ssl.xml
+++ b/jetty-server/src/main/config/etc/jetty-ssl.xml
@@ -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>
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ProxyConnectionFactory.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ProxyConnectionFactory.java
index 78904f89de..55baa87d1d 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/ProxyConnectionFactory.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ProxyConnectionFactory.java
@@ -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
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ProxyConnectionTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ProxyConnectionTest.java
index 1593372fdb..98c860f45f 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/ProxyConnectionTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ProxyConnectionTest.java
@@ -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);

Back to the top