View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2013 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.spdy.server.http;
20  
21  import java.util.Collections;
22  import java.util.Map;
23  
24  import org.eclipse.jetty.server.AbstractConnectionFactory;
25  import org.eclipse.jetty.server.ConnectionFactory;
26  import org.eclipse.jetty.server.HttpConfiguration;
27  import org.eclipse.jetty.server.HttpConnectionFactory;
28  import org.eclipse.jetty.server.Server;
29  import org.eclipse.jetty.server.ServerConnector;
30  import org.eclipse.jetty.spdy.api.SPDY;
31  import org.eclipse.jetty.spdy.server.NPNServerConnectionFactory;
32  import org.eclipse.jetty.util.ssl.SslContextFactory;
33  
34  public class HTTPSPDYServerConnector extends ServerConnector
35  {
36      public HTTPSPDYServerConnector(Server server)
37      {
38          this(server, Collections.<Short, PushStrategy>emptyMap());
39      }
40  
41      public HTTPSPDYServerConnector(Server server, SslContextFactory sslContextFactory)
42      {
43          this(server, sslContextFactory, Collections.<Short, PushStrategy>emptyMap());
44      }
45  
46      public HTTPSPDYServerConnector(Server server, Map<Short, PushStrategy> pushStrategies)
47      {
48          this(server, null, pushStrategies);
49      }
50  
51      public HTTPSPDYServerConnector(Server server, SslContextFactory sslContextFactory, Map<Short, PushStrategy> pushStrategies)
52      {
53          this(server, new HttpConfiguration(), sslContextFactory, pushStrategies);
54      }
55  
56      public HTTPSPDYServerConnector(Server server, short version, HttpConfiguration httpConfiguration, PushStrategy push)
57      {
58          super(server, new HTTPSPDYServerConnectionFactory(version, httpConfiguration, push));
59      }
60  
61      public HTTPSPDYServerConnector(Server server, HttpConfiguration config, SslContextFactory sslContextFactory, Map<Short, PushStrategy> pushStrategies)
62      {
63          super(server, AbstractConnectionFactory.getFactories(sslContextFactory,
64                  sslContextFactory == null
65                          ? new ConnectionFactory[]{new HttpConnectionFactory(config)}
66                          : new ConnectionFactory[]{new NPNServerConnectionFactory("spdy/3", "spdy/2", "http/1.1"),
67                          new HttpConnectionFactory(config),
68                          new HTTPSPDYServerConnectionFactory(SPDY.V3, config, getPushStrategy(SPDY.V3, pushStrategies)),
69                          new HTTPSPDYServerConnectionFactory(SPDY.V2, config, getPushStrategy(SPDY.V2, pushStrategies))}));
70          NPNServerConnectionFactory npnConnectionFactory = getConnectionFactory(NPNServerConnectionFactory.class);
71          if (npnConnectionFactory != null)
72              npnConnectionFactory.setDefaultProtocol("http/1.1");
73      }
74  
75      private static PushStrategy getPushStrategy(short version, Map<Short, PushStrategy> pushStrategies)
76      {
77          PushStrategy pushStrategy = pushStrategies.get(version);
78          if (pushStrategy == null)
79              pushStrategy = new PushStrategy.None();
80          return pushStrategy;
81      }
82  }