1 module hunt.http.codec.http.stream.AbstractHttp2Connection;
2 
3 import hunt.http.codec.http.decode.Parser;
4 import hunt.http.codec.http.encode.Http2Generator;
5 import hunt.http.codec.http.model;
6 
7 
8 import hunt.http.HttpConnection;
9 import hunt.http.codec.http.stream.BufferingFlowControlStrategy;
10 import hunt.http.codec.http.stream.FlowControlStrategy;
11 import hunt.http.codec.http.stream.Http2Session;
12 import hunt.http.codec.http.stream.Session;
13 import hunt.http.codec.http.stream.SimpleFlowControlStrategy;
14 
15 import hunt.http.HttpConnection;
16 import hunt.http.HttpOptions;
17 import hunt.http.HttpVersion;
18 
19 import hunt.net.secure.SecureSession;
20 import hunt.net.Connection;
21 
22 import hunt.Exceptions;
23 
24 alias Listener = hunt.http.codec.http.stream.Session.Session.Listener;
25 
26 abstract class AbstractHttp2Connection : AbstractHttpConnection  {
27 
28     protected Http2Session http2Session;
29     protected Parser parser;
30     protected Http2Generator generator;
31 
32     this(HttpOptions config, Connection tcpSession, Listener listener) {
33             
34         super(tcpSession, HttpVersion.HTTP_2);
35 
36         FlowControlStrategy flowControl;
37         switch (config.getFlowControlStrategy()) {
38             case "buffer":
39                 flowControl = new BufferingFlowControlStrategy(config.getInitialStreamSendWindow(), 0.5f);
40                 break;
41             case "simple":
42                 flowControl = new SimpleFlowControlStrategy(config.getInitialStreamSendWindow());
43                 break;
44             default:
45                 flowControl = new SimpleFlowControlStrategy(config.getInitialStreamSendWindow());
46                 break;
47         }
48         this.generator = new Http2Generator(config.getMaxDynamicTableSize(), config.getMaxHeaderBlockFragment());
49         this.http2Session = initHttp2Session(config, flowControl, listener);
50         this.parser = initParser(config);
51     }
52 
53     override
54     HttpConnectionType getConnectionType() {
55         return HttpConnectionType.HTTP2;
56     }
57 
58     abstract protected Http2Session initHttp2Session(HttpOptions config, FlowControlStrategy flowControl,
59                                                      Listener listener);
60 
61     abstract protected Parser initParser(HttpOptions config);
62 
63     StreamSession getHttp2Session() {
64         return http2Session;
65     }
66 
67 }