From 6dfa452e29ca3ea5ee63552f9cefb0dd07899fa3 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 7 Aug 2014 19:00:31 +1000 Subject: [PATCH] case insensitive protocols --- .../java/org/eclipse/jetty/embedded/LikeJettyXml.java | 3 ++- .../org/eclipse/jetty/embedded/ManyConnectors.java | 3 ++- .../org/eclipse/jetty/server/AbstractConnector.java | 11 ++++++----- .../eclipse/jetty/server/HttpConnectionFactory.java | 2 +- .../jetty/spdy/server/ALPNNegotiationTest.java | 2 +- .../jetty/websocket/server/SimpleServletServer.java | 3 ++- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java index b53f55cfc81..e6bde9223c3 100644 --- a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java +++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java @@ -23,6 +23,7 @@ import java.lang.management.ManagementFactory; import org.eclipse.jetty.deploy.DeploymentManager; import org.eclipse.jetty.deploy.PropertiesConfigurationManager; import org.eclipse.jetty.deploy.providers.WebAppProvider; +import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.jmx.MBeanContainer; import org.eclipse.jetty.security.HashLoginService; import org.eclipse.jetty.server.Handler; @@ -122,7 +123,7 @@ public class LikeJettyXml // SSL Connector ServerConnector sslConnector = new ServerConnector(server, - new SslConnectionFactory(sslContextFactory,"http/1.1"), + new SslConnectionFactory(sslContextFactory,HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(https_config)); sslConnector.setPort(8443); server.addConnector(sslConnector); diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ManyConnectors.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ManyConnectors.java index 78e595909b5..4bca8dfa9f5 100644 --- a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ManyConnectors.java +++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ManyConnectors.java @@ -18,6 +18,7 @@ package org.eclipse.jetty.embedded; +import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory; @@ -83,7 +84,7 @@ public class ManyConnectors // We create a second ServerConnector, passing in the http configuration we just made along with the // previously created ssl context factory. Next we set the port and a longer idle timeout. ServerConnector https = new ServerConnector(server, - new SslConnectionFactory(sslContextFactory,"http/1.1"), + new SslConnectionFactory(sslContextFactory,HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(https_config)); https.setPort(8443); https.setIdleTimeout(500000); 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 89d22129cce..893de2f9d62 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 @@ -37,6 +37,7 @@ import org.eclipse.jetty.io.ArrayByteBufferPool; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.util.FutureCallback; +import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.component.ContainerLifeCycle; @@ -337,7 +338,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co { synchronized (_factories) { - return _factories.get(protocol); + return _factories.get(StringUtil.asciiToLowerCase(protocol)); } } @@ -357,7 +358,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co { synchronized (_factories) { - String key=factory.getProtocol(); + String key=StringUtil.asciiToLowerCase(factory.getProtocol()); ConnectionFactory old=_factories.remove(key); if (old!=null) { @@ -378,7 +379,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co { synchronized (_factories) { - String key=factory.getProtocol(); + String key=StringUtil.asciiToLowerCase(factory.getProtocol()); if (_factories.containsKey(key)) LOG.info("{} addIfAbsent ignored {}",this,factory); else @@ -396,7 +397,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co { synchronized (_factories) { - ConnectionFactory factory= _factories.remove(protocol); + ConnectionFactory factory= _factories.remove(StringUtil.asciiToLowerCase(protocol)); removeBean(factory); return factory; } @@ -451,7 +452,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co public void setDefaultProtocol(String defaultProtocol) { - _defaultProtocol = defaultProtocol; + _defaultProtocol = StringUtil.asciiToLowerCase(defaultProtocol); if (isRunning()) _defaultConnectionFactory=getConnectionFactory(_defaultProtocol); } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnectionFactory.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnectionFactory.java index ce6ffdb7b4b..d8790748126 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnectionFactory.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnectionFactory.java @@ -44,7 +44,7 @@ public class HttpConnectionFactory extends AbstractConnectionFactory implements public HttpConnectionFactory(@Name("config") HttpConfiguration config) { - super(HttpVersion.HTTP_1_1.toString()); + super(HttpVersion.HTTP_1_1.asString()); _config=config; addBean(_config); } diff --git a/jetty-spdy/spdy-alpn-tests/src/test/java/org/eclipse/jetty/spdy/server/ALPNNegotiationTest.java b/jetty-spdy/spdy-alpn-tests/src/test/java/org/eclipse/jetty/spdy/server/ALPNNegotiationTest.java index 0f3c4be759b..d471f768b5d 100644 --- a/jetty-spdy/spdy-alpn-tests/src/test/java/org/eclipse/jetty/spdy/server/ALPNNegotiationTest.java +++ b/jetty-spdy/spdy-alpn-tests/src/test/java/org/eclipse/jetty/spdy/server/ALPNNegotiationTest.java @@ -133,7 +133,7 @@ public class ALPNNegotiationTest extends AbstractALPNTest @Override public void selected(String protocol) { - Assert.assertEquals("http/1.1", protocol); + Assert.assertEquals("http/1.1", protocol.toLowerCase()); } }); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/SimpleServletServer.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/SimpleServletServer.java index 4ec28fb229a..1b05cdd6b2f 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/SimpleServletServer.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/SimpleServletServer.java @@ -22,6 +22,7 @@ import java.net.URI; import javax.servlet.http.HttpServlet; +import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory; import org.eclipse.jetty.server.SecureRequestCustomizer; @@ -100,7 +101,7 @@ public class SimpleServletServer https_config.addCustomizer(new SecureRequestCustomizer()); // SSL Connector - connector = new ServerConnector(server,new SslConnectionFactory(sslContextFactory,"http/1.1"),new HttpConnectionFactory(https_config)); + connector = new ServerConnector(server,new SslConnectionFactory(sslContextFactory,HttpVersion.HTTP_1_1.asString()),new HttpConnectionFactory(https_config)); connector.setPort(0); } else