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      private boolean _recordHttpComplianceViolations = false;
37  
38      public HttpConnectionFactory()
39      {
40          this(new HttpConfiguration());
41      }
42      
43      public HttpConnectionFactory(@Name("config") HttpConfiguration config)
44      {
45          this(config,null);
46      }
47  
48      public HttpConnectionFactory(@Name("config") HttpConfiguration config, @Name("compliance") HttpCompliance compliance)
49      {
50          super(HttpVersion.HTTP_1_1.asString());
51          _config=config;
52          _httpCompliance=compliance==null?HttpCompliance.RFC7230:compliance;
53          if (config==null)
54              throw new IllegalArgumentException("Null HttpConfiguration");
55          addBean(_config);
56      }
57  
58      @Override
59      public HttpConfiguration getHttpConfiguration()
60      {
61          return _config;
62      }
63  
64      public HttpCompliance getHttpCompliance()
65      {
66          return _httpCompliance;
67      }
68  
69      public boolean isRecordHttpComplianceViolations()
70      {
71          return _recordHttpComplianceViolations;
72      }
73  
74      /**
75       * @param httpCompliance String value of {@link HttpCompliance}
76       */
77      public void setHttpCompliance(HttpCompliance httpCompliance)
78      {
79          _httpCompliance = httpCompliance;
80      }
81  
82      @Override
83      public Connection newConnection(Connector connector, EndPoint endPoint)
84      {
85          HttpConnection conn = new HttpConnection(_config, connector, endPoint, _httpCompliance,isRecordHttpComplianceViolations());
86          return configure(conn, connector, endPoint);
87      }
88      
89      
90      public void setRecordHttpComplianceViolations(boolean recordHttpComplianceViolations)
91      {
92          this._recordHttpComplianceViolations = recordHttpComplianceViolations;
93      }
94  }