1 module hunt.http.server.Http2ServerConnection;
2 
3 import hunt.http.server.HttpServerConnection;
4 import hunt.http.server.Http2ServerRequestHandler;
5 import hunt.http.server.Http2ServerSession;
6 import hunt.http.server.ServerSessionListener;
7 
8 import hunt.http.codec.http.decode.Parser;
9 import hunt.http.codec.http.decode.ServerParser;
10 import hunt.http.codec.http.encode.Http2Generator;
11 import hunt.http.codec.http.stream;
12 
13 import hunt.http.HttpConnection;
14 import hunt.http.HttpOptions;
15 import hunt.http.HttpOutputStream;
16 
17 import hunt.net.secure.SecureSession;
18 import hunt.net.Connection;
19 
20 import hunt.concurrency.FuturePromise;
21 import hunt.concurrency.Promise;
22 import hunt.Exceptions;
23 
24 alias Listener = hunt.http.codec.http.stream.Session.Session.Listener;
25 
26 class Http2ServerConnection : AbstractHttp2Connection , HttpServerConnection {
27 
28     this(HttpOptions config, Connection tcpSession, 
29                                  ServerSessionListener serverSessionListener) {
30         super(config, tcpSession, serverSessionListener);
31         if (typeid(serverSessionListener) == typeid(Http2ServerRequestHandler)) {
32             Http2ServerRequestHandler handler = cast(Http2ServerRequestHandler) serverSessionListener;
33             handler.connection = this;
34         }
35     }
36 
37     override
38     protected Http2Session initHttp2Session(HttpOptions config, FlowControlStrategy flowControl,
39                                             Listener listener) {
40         Http2ServerSession http2ServerSession = new Http2ServerSession(null, this._tcpSession, this.generator,
41                 cast(ServerSessionListener) listener, flowControl, config.getStreamIdleTimeout());
42         http2ServerSession.setMaxLocalStreams(config.getMaxConcurrentStreams());
43         http2ServerSession.setMaxRemoteStreams(config.getMaxConcurrentStreams());
44         http2ServerSession.setInitialSessionRecvWindow(config.getInitialSessionRecvWindow());
45         return http2ServerSession;
46     }
47 
48     override
49     protected Parser initParser(HttpOptions config) {
50         return new ServerParser(cast(Http2ServerSession) http2Session, config.getMaxDynamicTableSize(), config.getMaxRequestHeadLength());
51     }
52 
53     override
54     HttpConnectionType getConnectionType() {
55         return super.getConnectionType();
56     }
57 
58     // override
59     // bool isSecured() {
60     //     return super.isSecured();
61     // }
62 
63     ServerParser getParser() {
64         return cast(ServerParser) parser;
65     }
66 
67     Http2Generator getGenerator() {
68         return generator;
69     }
70 
71     SessionSPI getSessionSPI() {
72         return http2Session;
73     }
74 
75     override
76     void upgradeHttpTunnel(Promise!HttpTunnelConnection promise) {
77         throw new IllegalStateException("the http2 connection can not upgrade to http tunnel");
78     }
79 
80     override
81     FuturePromise!HttpTunnelConnection upgradeHttpTunnel() {
82         throw new IllegalStateException("the http2 connection can not upgrade to http tunnel");
83     }
84 }