support h2-15 and h2-14
This commit is contained in:
parent
593cb39059
commit
5b60e0c98d
|
@ -43,7 +43,7 @@ public abstract class AbstractHTTP2ServerConnectionFactory extends AbstractConne
|
|||
|
||||
public AbstractHTTP2ServerConnectionFactory()
|
||||
{
|
||||
super("h2-14");
|
||||
super("h2-15","h2-14");
|
||||
}
|
||||
|
||||
public boolean isDispatchIO()
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
|
||||
package org.eclipse.jetty.server;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.io.AbstractConnection;
|
||||
import org.eclipse.jetty.io.Connection;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
|
@ -28,11 +32,19 @@ import org.eclipse.jetty.util.ssl.SslContextFactory;
|
|||
public abstract class AbstractConnectionFactory extends ContainerLifeCycle implements ConnectionFactory
|
||||
{
|
||||
private final String _protocol;
|
||||
private final List<String> _protocols;
|
||||
private int _inputbufferSize = 8192;
|
||||
|
||||
protected AbstractConnectionFactory(String protocol)
|
||||
{
|
||||
_protocol=protocol;
|
||||
_protocols=Collections.unmodifiableList(Arrays.asList(new String[]{protocol}));
|
||||
}
|
||||
|
||||
protected AbstractConnectionFactory(String... protocols)
|
||||
{
|
||||
_protocol=protocols[0];
|
||||
_protocols=Collections.unmodifiableList(Arrays.asList(protocols));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,6 +53,12 @@ public abstract class AbstractConnectionFactory extends ContainerLifeCycle imple
|
|||
return _protocol;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getProtocols()
|
||||
{
|
||||
return _protocols;
|
||||
}
|
||||
|
||||
public int getInputBufferSize()
|
||||
{
|
||||
return _inputbufferSize;
|
||||
|
@ -67,7 +85,7 @@ public abstract class AbstractConnectionFactory extends ContainerLifeCycle imple
|
|||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s@%x{%s}",this.getClass().getSimpleName(),hashCode(),getProtocol());
|
||||
return String.format("%s@%x%s",this.getClass().getSimpleName(),hashCode(),getProtocols());
|
||||
}
|
||||
|
||||
public static ConnectionFactory[] getFactories(SslContextFactory sslContextFactory, ConnectionFactory... factories)
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -358,17 +359,33 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co
|
|||
{
|
||||
synchronized (_factories)
|
||||
{
|
||||
String key=StringUtil.asciiToLowerCase(factory.getProtocol());
|
||||
ConnectionFactory old=_factories.remove(key);
|
||||
if (old!=null)
|
||||
Set<ConnectionFactory> to_remove = new HashSet<ConnectionFactory>();
|
||||
for (String key:factory.getProtocols())
|
||||
{
|
||||
key=StringUtil.asciiToLowerCase(key);
|
||||
ConnectionFactory old=_factories.remove(key);
|
||||
if (old!=null)
|
||||
{
|
||||
if (old.getProtocol().equals(_defaultProtocol))
|
||||
_defaultProtocol=null;
|
||||
to_remove.add(old);
|
||||
}
|
||||
_factories.put(key, factory);
|
||||
}
|
||||
|
||||
// keep factories still referenced
|
||||
for (ConnectionFactory f : _factories.values())
|
||||
to_remove.remove(f);
|
||||
|
||||
// remove old factories
|
||||
for (ConnectionFactory old: to_remove)
|
||||
{
|
||||
if (old.getProtocol().equals(_defaultProtocol))
|
||||
_defaultProtocol=null;
|
||||
removeBean(old);
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("{} removed {}", this, old);
|
||||
}
|
||||
_factories.put(key, factory);
|
||||
|
||||
// add new Bean
|
||||
addBean(factory);
|
||||
if (_defaultProtocol==null)
|
||||
_defaultProtocol=factory.getProtocol();
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
package org.eclipse.jetty.server;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.io.Connection;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
|
||||
|
@ -42,9 +44,15 @@ public interface ConnectionFactory
|
|||
{
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return A string representing the protocol name.
|
||||
* @return A string representing the primary protocol name.
|
||||
*/
|
||||
public String getProtocol();
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return A list of alternative protocol names/versions including the primary protocol.
|
||||
*/
|
||||
public List<String> getProtocols();
|
||||
|
||||
/**
|
||||
* <p>Creates a new {@link Connection} with the given parameters</p>
|
||||
|
|
|
@ -52,21 +52,21 @@ public abstract class NegotiatingServerConnectionFactory extends AbstractConnect
|
|||
}
|
||||
}
|
||||
|
||||
private final List<String> protocols;
|
||||
private final List<String> negotiatedProtocols;
|
||||
private String defaultProtocol;
|
||||
|
||||
public NegotiatingServerConnectionFactory(String protocol, String... protocols)
|
||||
public NegotiatingServerConnectionFactory(String protocol, String... negotiatedProtocols)
|
||||
{
|
||||
super(protocol);
|
||||
this.protocols = new ArrayList<>();
|
||||
if (protocols != null)
|
||||
this.negotiatedProtocols = new ArrayList<>();
|
||||
if (negotiatedProtocols != null)
|
||||
{
|
||||
// Trim the values, as they may come from XML configuration.
|
||||
for (String p : protocols)
|
||||
for (String p : negotiatedProtocols)
|
||||
{
|
||||
p = p.trim();
|
||||
if (!p.isEmpty())
|
||||
this.protocols.add(p.trim());
|
||||
this.negotiatedProtocols.add(p.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -83,34 +83,37 @@ public abstract class NegotiatingServerConnectionFactory extends AbstractConnect
|
|||
this.defaultProtocol = dft.isEmpty() ? null : dft;
|
||||
}
|
||||
|
||||
public List<String> getProtocols()
|
||||
public List<String> getNegotiatedProtocols()
|
||||
{
|
||||
return protocols;
|
||||
return negotiatedProtocols;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection newConnection(Connector connector, EndPoint endPoint)
|
||||
{
|
||||
List<String> protocols = this.protocols;
|
||||
if (protocols.isEmpty())
|
||||
List<String> negotiated = this.negotiatedProtocols;
|
||||
if (negotiated.isEmpty())
|
||||
{
|
||||
protocols = connector.getProtocols();
|
||||
Iterator<String> i = protocols.iterator();
|
||||
while (i.hasNext())
|
||||
// Generate list of protocols that we can negotiate
|
||||
negotiated = new ArrayList<>(connector.getProtocols());
|
||||
for (Iterator<String> i = negotiated.iterator();i.hasNext();)
|
||||
{
|
||||
String protocol = i.next();
|
||||
if ("ssl".equalsIgnoreCase(protocol) ||
|
||||
"alpn".equalsIgnoreCase(protocol) ||
|
||||
"npn".equalsIgnoreCase(protocol))
|
||||
// exclude SSL and negotiating protocols
|
||||
ConnectionFactory f = connector.getConnectionFactory(protocol);
|
||||
|
||||
if ((f instanceof SslConnectionFactory) ||
|
||||
(f instanceof NegotiatingServerConnectionFactory))
|
||||
{
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if default protocol is not set, then it is the first protocol given
|
||||
String dft = defaultProtocol;
|
||||
if (dft == null && !protocols.isEmpty())
|
||||
dft = protocols.get(0);
|
||||
if (dft == null && !negotiated.isEmpty())
|
||||
dft = negotiated.get(0);
|
||||
|
||||
SSLEngine engine = null;
|
||||
EndPoint ep = endPoint;
|
||||
|
@ -123,7 +126,7 @@ public abstract class NegotiatingServerConnectionFactory extends AbstractConnect
|
|||
ep = null;
|
||||
}
|
||||
|
||||
return configure(newServerConnection(connector, endPoint, engine, protocols, dft), connector, endPoint);
|
||||
return configure(newServerConnection(connector, endPoint, engine, negotiated, dft), connector, endPoint);
|
||||
}
|
||||
|
||||
protected abstract AbstractConnection newServerConnection(Connector connector, EndPoint endPoint, SSLEngine engine, List<String> protocols, String defaultProtocol);
|
||||
|
@ -131,6 +134,6 @@ public abstract class NegotiatingServerConnectionFactory extends AbstractConnect
|
|||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s@%x{%s,%s,%s}", getClass().getSimpleName(), hashCode(), getProtocol(), getDefaultProtocol(), getProtocols());
|
||||
return String.format("%s@%x{%s,%s,%s}", getClass().getSimpleName(), hashCode(), getProtocols(), getDefaultProtocol(), getNegotiatedProtocols());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue