View Javadoc

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  import org.eclipse.jetty.http.HttpCompliance;
22  import org.eclipse.jetty.http.HttpVersion;
23  import org.eclipse.jetty.io.Connection;
24  import org.eclipse.jetty.io.EndPoint;
25  import org.eclipse.jetty.util.annotation.Name;
26  
27  /** A Connection Factory for HTTP Connections.
28   * <p>Accepts connections either directly or via SSL and/or ALPN chained connection factories.  The accepted
29   * {@link HttpConnection}s are configured by a {@link HttpConfiguration} instance that is either created by
30   * default or passed in to the constructor.
31   */
32  public class HttpConnectionFactory extends AbstractConnectionFactory implements HttpConfiguration.ConnectionFactory
33  {
34      private final HttpConfiguration _config;
35      private HttpCompliance _httpCompliance;
36  
37      public HttpConnectionFactory()
38      {
39          this(new HttpConfiguration());
40      }
41      
42      public HttpConnectionFactory(@Name("config") HttpConfiguration config)
43      {
44          this(config,null);
45      }
46  
47      public HttpConnectionFactory(@Name("config") HttpConfiguration config, @Name("compliance") HttpCompliance compliance)
48      {
49          super(HttpVersion.HTTP_1_1.asString());
50          _config=config;
51          _httpCompliance=compliance==null?HttpCompliance.RFC7230:compliance;
52          if (config==null)
53              throw new IllegalArgumentException("Null HttpConfiguration");
54          addBean(_config);
55      }
56  
57      @Override
58      public HttpConfiguration getHttpConfiguration()
59      {
60          return _config;
61      }
62  
63      public HttpCompliance getHttpCompliance()
64      {
65          return _httpCompliance;
66      }
67  
68      /**
69       * @param httpCompliance String value of {@link HttpCompliance}
70       */
71      public void setHttpCompliance(HttpCompliance httpCompliance)
72      {
73          _httpCompliance = httpCompliance;
74      }
75  
76      @Override
77      public Connection newConnection(Connector connector, EndPoint endPoint)
78      {
79          return configure(new HttpConnection(_config, connector, endPoint, _httpCompliance), connector, endPoint);
80      }
81      
82      
83  }