1 // 2 // ======================================================================== 3 // Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd. 4 // ------------------------------------------------------------------------ 5 // All rights reserved. This program and the accompanying materials 6 // are made available under the terms of the Eclipse Public License v1.0 7 // and Apache License v2.0 which accompanies this distribution. 8 // 9 // The Eclipse Public License is available at 10 // http://www.eclipse.org/legal/epl-v10.html 11 // 12 // The Apache License v2.0 is available at 13 // http://www.opensource.org/licenses/apache2.0.php 14 // 15 // You may elect to redistribute this code under either of these licenses. 16 // ======================================================================== 17 // 18 19 package org.eclipse.jetty.server; 20 21 22 import java.util.List; 23 24 import org.eclipse.jetty.http.BadMessageException; 25 import org.eclipse.jetty.http.HttpFields; 26 import org.eclipse.jetty.http.MetaData; 27 import org.eclipse.jetty.io.Connection; 28 import org.eclipse.jetty.io.EndPoint; 29 30 /** 31 * A Factory to create {@link Connection} instances for {@link Connector}s. 32 * <p> 33 * A Connection factory is responsible for instantiating and configuring a {@link Connection} instance 34 * to handle an {@link EndPoint} accepted by a {@link Connector}. 35 * <p> 36 * A ConnectionFactory has a protocol name that represents the protocol of the Connections 37 * created. Example of protocol names include: 38 * <dl> 39 * <dt>http</dt><dd>Creates a HTTP connection that can handle multiple versions of HTTP from 0.9 to 1.1</dd> 40 * <dt>h2</dt><dd>Creates a HTTP/2 connection that handles the HTTP/2 protocol</dd> 41 * <dt>SSL-XYZ</dt><dd>Create an SSL connection chained to a connection obtained from a connection factory 42 * with a protocol "XYZ".</dd> 43 * <dt>SSL-http</dt><dd>Create an SSL connection chained to a HTTP connection (aka https)</dd> 44 * <dt>SSL-ALPN</dt><dd>Create an SSL connection chained to a ALPN connection, that uses a negotiation with 45 * the client to determine the next protocol.</dd> 46 * </dl> 47 */ 48 public interface ConnectionFactory 49 { 50 /* ------------------------------------------------------------ */ 51 /** 52 * @return A string representing the primary protocol name. 53 */ 54 public String getProtocol(); 55 56 /* ------------------------------------------------------------ */ 57 /** 58 * @return A list of alternative protocol names/versions including the primary protocol. 59 */ 60 public List<String> getProtocols(); 61 62 /** 63 * <p>Creates a new {@link Connection} with the given parameters</p> 64 * @param connector The {@link Connector} creating this connection 65 * @param endPoint the {@link EndPoint} associated with the connection 66 * @return a new {@link Connection} 67 */ 68 public Connection newConnection(Connector connector, EndPoint endPoint); 69 70 71 public interface Upgrading extends ConnectionFactory 72 { 73 /* ------------------------------------------------------------ */ 74 /** Create a connection for an upgrade request. 75 * <p>This is a variation of {@link #newConnection(Connector, EndPoint)} that can create (and/or customise) 76 * a connection for an upgrade request. Implementations may call {@link #newConnection(Connector, EndPoint)} or 77 * may construct the connection instance themselves.</p> 78 * 79 * @param connector The connector to upgrade for. 80 * @param endPoint The endpoint of the connection. 81 * @param upgradeRequest The meta data of the upgrade request. 82 * @param responseFields The fields to be sent with the 101 response 83 * @return Null to indicate that request processing should continue normally without upgrading. A new connection instance to 84 * indicate that the upgrade should proceed. 85 * @throws BadMessageException Thrown to indicate the upgrade attempt was illegal and that a bad message response should be sent. 86 */ 87 public Connection upgradeConnection(Connector connector, EndPoint endPoint, MetaData.Request upgradeRequest,HttpFields responseFields) throws BadMessageException; 88 } 89 }