diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnectionFactory.java b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnectionFactory.java index ac7079eea89..2bb76ccbd5c 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnectionFactory.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnectionFactory.java @@ -89,12 +89,17 @@ public abstract class AbstractConnectionFactory extends ContainerLifeCycle imple } protected String findNextProtocol(Connector connector) + { + return findNextProtocol(connector, getProtocol()); + } + + protected static String findNextProtocol(Connector connector, String currentProtocol) { String nextProtocol = null; for (Iterator it = connector.getProtocols().iterator(); it.hasNext(); ) { String protocol = it.next(); - if (getProtocol().equalsIgnoreCase(protocol)) + if (currentProtocol.equalsIgnoreCase(protocol)) { nextProtocol = it.hasNext() ? it.next() : null; break; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java index ab4d153f65a..30991980829 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java @@ -36,6 +36,7 @@ import java.util.concurrent.Executor; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Condition; +import java.util.stream.Collectors; import org.eclipse.jetty.io.ArrayByteBufferPool; import org.eclipse.jetty.io.ByteBufferPool; @@ -776,9 +777,9 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co @Override public String toString() { - return String.format("%s@%x{%s,%s}", + return String.format("%s@%x{%s, %s}", _name == null ? getClass().getSimpleName() : _name, hashCode(), - getDefaultProtocol(), getProtocols()); + getDefaultProtocol(), getProtocols().stream().collect(Collectors.joining(", ", "(", ")"))); } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/DetectorConnectionFactory.java b/jetty-server/src/main/java/org/eclipse/jetty/server/DetectorConnectionFactory.java index 3f280a674d4..5b28db46111 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/DetectorConnectionFactory.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/DetectorConnectionFactory.java @@ -64,7 +64,7 @@ public class DetectorConnectionFactory extends AbstractConnectionFactory impleme // remove protocol duplicates while keeping their ordering -> use LinkedHashSet LinkedHashSet protocols = Arrays.stream(detectingConnectionFactories).map(ConnectionFactory::getProtocol).collect(Collectors.toCollection(LinkedHashSet::new)); - String protocol = String.join("|", protocols); + String protocol = protocols.stream().collect(Collectors.joining("|", "[", "]")); if (LOG.isDebugEnabled()) LOG.debug("Detector generated protocol name : {}", protocol); return protocol; 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 d895e120055..2f4b699307c 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 @@ -60,15 +60,16 @@ public class ProxyConnectionFactory extends DetectorConnectionFactory super(new ProxyV1ConnectionFactory(nextProtocol), new ProxyV2ConnectionFactory(nextProtocol)); } - private static ConnectionFactory findNextConnectionFactory(String nextProtocol, Connector connector, AbstractConnectionFactory currentConnectionFactory, EndPoint endp) + private static ConnectionFactory findNextConnectionFactory(String nextProtocol, Connector connector, String currentProtocol, EndPoint endp) { + currentProtocol = "[" + currentProtocol + "]"; if (LOG.isDebugEnabled()) - LOG.debug("finding next connection factory for protocol {}", nextProtocol); + LOG.debug("finding connection factory following {} for protocol {}", currentProtocol, nextProtocol); String nextProtocolToFind = nextProtocol; if (nextProtocol == null) - nextProtocolToFind = currentConnectionFactory.findNextProtocol(connector); + nextProtocolToFind = AbstractConnectionFactory.findNextProtocol(connector, currentProtocol); if (nextProtocolToFind == null) - throw new IllegalStateException("Cannot find protocol following '" + currentConnectionFactory.getProtocol() + "' in connector's protocol list " + connector.getProtocols() + " for " + endp); + throw new IllegalStateException("Cannot find protocol following '" + currentProtocol + "' in connector's protocol list " + connector.getProtocols() + " for " + endp); ConnectionFactory connectionFactory = connector.getConnectionFactory(nextProtocolToFind); if (connectionFactory == null) throw new IllegalStateException("Cannot find protocol '" + nextProtocol + "' in connector's protocol list " + connector.getProtocols() + " for " + endp); @@ -133,7 +134,7 @@ public class ProxyConnectionFactory extends DetectorConnectionFactory @Override public Connection newConnection(Connector connector, EndPoint endp) { - ConnectionFactory nextConnectionFactory = findNextConnectionFactory(_nextProtocol, connector, this, endp); + ConnectionFactory nextConnectionFactory = findNextConnectionFactory(_nextProtocol, connector, getProtocol(), endp); return configure(new ProxyProtocolV1Connection(endp, connector, nextConnectionFactory), connector, endp); } @@ -414,7 +415,7 @@ public class ProxyConnectionFactory extends DetectorConnectionFactory @Override public Connection newConnection(Connector connector, EndPoint endp) { - ConnectionFactory nextConnectionFactory = findNextConnectionFactory(_nextProtocol, connector, this, endp); + ConnectionFactory nextConnectionFactory = findNextConnectionFactory(_nextProtocol, connector, getProtocol(), endp); return configure(new ProxyProtocolV2Connection(endp, connector, nextConnectionFactory), connector, endp); } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/DetectorConnectionTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/DetectorConnectionTest.java index 2663338b279..6f99f24264b 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/DetectorConnectionTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/DetectorConnectionTest.java @@ -630,8 +630,8 @@ public class DetectorConnectionTest ProxyConnectionFactory proxy = new ProxyConnectionFactory(HttpVersion.HTTP_1_1.asString()); SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()); - assertEquals("SSL|proxy", new DetectorConnectionFactory(ssl, proxy).getProtocol()); - assertEquals("proxy|SSL", new DetectorConnectionFactory(proxy, ssl).getProtocol()); + assertEquals("[SSL|[proxy]]", new DetectorConnectionFactory(ssl, proxy).getProtocol()); + assertEquals("[[proxy]|SSL]", new DetectorConnectionFactory(proxy, ssl).getProtocol()); } @Test 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 9f709e2b08a..9aa38e3554d 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 @@ -247,7 +247,7 @@ public class ProxyConnectionTest { p.customize((connector) -> { - ProxyConnectionFactory factory = (ProxyConnectionFactory)connector.getConnectionFactory("proxy"); + ProxyConnectionFactory factory = (ProxyConnectionFactory)connector.getConnectionFactory("[proxy]"); factory.setMaxProxyHeader(11); // just one byte short }); String proxy =