1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.http2.server;
20
21 import java.util.Objects;
22
23 import org.eclipse.jetty.http2.BufferingFlowControlStrategy;
24 import org.eclipse.jetty.http2.FlowControlStrategy;
25 import org.eclipse.jetty.http2.HTTP2Connection;
26 import org.eclipse.jetty.http2.api.server.ServerSessionListener;
27 import org.eclipse.jetty.http2.generator.Generator;
28 import org.eclipse.jetty.http2.parser.ServerParser;
29 import org.eclipse.jetty.io.Connection;
30 import org.eclipse.jetty.io.EndPoint;
31 import org.eclipse.jetty.server.AbstractConnectionFactory;
32 import org.eclipse.jetty.server.Connector;
33 import org.eclipse.jetty.server.HttpConfiguration;
34 import org.eclipse.jetty.util.annotation.Name;
35
36 public abstract class AbstractHTTP2ServerConnectionFactory extends AbstractConnectionFactory
37 {
38 private int maxDynamicTableSize = 4096;
39 private int initialStreamSendWindow = FlowControlStrategy.DEFAULT_WINDOW_SIZE;
40 private int maxConcurrentStreams = -1;
41 private int maxHeaderBlockFragment = 0;
42 private final HttpConfiguration httpConfiguration;
43
44 public AbstractHTTP2ServerConnectionFactory(@Name("config") HttpConfiguration httpConfiguration)
45 {
46 this(httpConfiguration,"h2","h2-17","h2-16","h2-15","h2-14");
47 }
48
49 protected AbstractHTTP2ServerConnectionFactory(@Name("config") HttpConfiguration httpConfiguration, String... protocols)
50 {
51 super(protocols);
52 this.httpConfiguration = Objects.requireNonNull(httpConfiguration);
53 }
54
55 public int getMaxDynamicTableSize()
56 {
57 return maxDynamicTableSize;
58 }
59
60 public void setMaxDynamicTableSize(int maxDynamicTableSize)
61 {
62 this.maxDynamicTableSize = maxDynamicTableSize;
63 }
64
65 public int getInitialStreamSendWindow()
66 {
67 return initialStreamSendWindow;
68 }
69
70 public void setInitialStreamSendWindow(int initialStreamSendWindow)
71 {
72 this.initialStreamSendWindow = initialStreamSendWindow;
73 }
74
75 public int getMaxConcurrentStreams()
76 {
77 return maxConcurrentStreams;
78 }
79
80 public void setMaxConcurrentStreams(int maxConcurrentStreams)
81 {
82 this.maxConcurrentStreams = maxConcurrentStreams;
83 }
84
85 public int getMaxHeaderBlockFragment()
86 {
87 return maxHeaderBlockFragment;
88 }
89
90 public void setMaxHeaderBlockFragment(int maxHeaderBlockFragment)
91 {
92 this.maxHeaderBlockFragment = maxHeaderBlockFragment;
93 }
94
95 public HttpConfiguration getHttpConfiguration()
96 {
97 return httpConfiguration;
98 }
99
100 @Override
101 public Connection newConnection(Connector connector, EndPoint endPoint)
102 {
103 ServerSessionListener listener = newSessionListener(connector, endPoint);
104
105 Generator generator = new Generator(connector.getByteBufferPool(), getMaxDynamicTableSize(), getMaxHeaderBlockFragment());
106 FlowControlStrategy flowControl = newFlowControlStrategy();
107 HTTP2ServerSession session = new HTTP2ServerSession(connector.getScheduler(), endPoint, generator, listener, flowControl);
108 session.setMaxLocalStreams(getMaxConcurrentStreams());
109 session.setMaxRemoteStreams(getMaxConcurrentStreams());
110
111
112
113
114 session.setStreamIdleTimeout(endPoint.getIdleTimeout());
115
116 ServerParser parser = newServerParser(connector, session);
117 HTTP2Connection connection = new HTTP2ServerConnection(connector.getByteBufferPool(), connector.getExecutor(),
118 endPoint, httpConfiguration, parser, session, getInputBufferSize(), listener);
119
120 return configure(connection, connector, endPoint);
121 }
122
123 protected FlowControlStrategy newFlowControlStrategy()
124 {
125 return new BufferingFlowControlStrategy(getInitialStreamSendWindow(), 0.5F);
126 }
127
128 protected abstract ServerSessionListener newSessionListener(Connector connector, EndPoint endPoint);
129
130 protected ServerParser newServerParser(Connector connector, ServerParser.Listener listener)
131 {
132 return new ServerParser(connector.getByteBufferPool(), listener, getMaxDynamicTableSize(), getHttpConfiguration().getRequestHeaderSize());
133 }
134 }