From d68c286499e91a3097a498eb882fbeef4ce2ad57 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Wed, 28 Mar 2018 19:55:58 +0200 Subject: [PATCH] Fixes #2145 - Enabled h2, http/1.1 + https failed with invalid preface. Now using HttpVersion.HTTP_1_1::is, which is case insensitive, to find the default protocol among the negotiated protocols. Signed-off-by: Simone Bordet --- .../NegotiatingServerConnectionFactory.java | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/NegotiatingServerConnectionFactory.java b/jetty-server/src/main/java/org/eclipse/jetty/server/NegotiatingServerConnectionFactory.java index 42590e18ac8..4eafd91a373 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/NegotiatingServerConnectionFactory.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/NegotiatingServerConnectionFactory.java @@ -32,7 +32,6 @@ import org.eclipse.jetty.io.ssl.SslConnection; public abstract class NegotiatingServerConnectionFactory extends AbstractConnectionFactory { - private final List negotiatedProtocols; private String defaultProtocol; @@ -47,7 +46,7 @@ public abstract class NegotiatingServerConnectionFactory extends AbstractConnect { p = p.trim(); if (!p.isEmpty()) - this.negotiatedProtocols.add(p.trim()); + this.negotiatedProtocols.add(p); } } } @@ -75,25 +74,25 @@ public abstract class NegotiatingServerConnectionFactory extends AbstractConnect List negotiated = this.negotiatedProtocols; if (negotiated.isEmpty()) { - // Generate list of protocols that we can negotiate + // Generate list of protocols that we can negotiate. negotiated = connector.getProtocols().stream() - .filter(p-> - { - ConnectionFactory f=connector.getConnectionFactory(p); - return !(f instanceof SslConnectionFactory)&&!(f instanceof NegotiatingServerConnectionFactory); - }) - .collect(Collectors.toList()); + .filter(p -> + { + ConnectionFactory f = connector.getConnectionFactory(p); + return !(f instanceof SslConnectionFactory) && !(f instanceof NegotiatingServerConnectionFactory); + }) + .collect(Collectors.toList()); } - // if default protocol is not set, then it is either HTTP/1.1 or - // the first protocol given + // If default protocol is not set, then it is + // either HTTP/1.1 or the first protocol given. String dft = defaultProtocol; if (dft == null && !negotiated.isEmpty()) { - if (negotiated.contains(HttpVersion.HTTP_1_1.asString())) - dft = HttpVersion.HTTP_1_1.asString(); - else - dft = negotiated.get(0); + dft = negotiated.stream() + .filter(HttpVersion.HTTP_1_1::is) + .findFirst() + .orElse(negotiated.get(0)); } SSLEngine engine = null;