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 12 import hunt.http.codec.http.stream; 13 14 import hunt.net.ConnectionType; 15 import hunt.net.secure.SecureSession; 16 import hunt.net.Session; 17 18 import hunt.util.concurrent.CompletableFuture; 19 import hunt.util.concurrent.Promise; 20 import hunt.lang.exception; 21 22 alias Listener = hunt.http.codec.http.stream.Session.Session.Listener; 23 24 class Http2ServerConnection : AbstractHttp2Connection , HttpServerConnection { 25 26 this(Http2Configuration config, TcpSession tcpSession, SecureSession secureSession, 27 ServerSessionListener serverSessionListener) { 28 super(config, tcpSession, secureSession, serverSessionListener); 29 if (typeid(serverSessionListener) == typeid(Http2ServerRequestHandler)) { 30 Http2ServerRequestHandler handler = cast(Http2ServerRequestHandler) serverSessionListener; 31 handler.connection = this; 32 } 33 } 34 35 override 36 protected Http2Session initHttp2Session(Http2Configuration config, FlowControlStrategy flowControl, 37 Listener listener) { 38 Http2ServerSession http2ServerSession = new Http2ServerSession(null, this.tcpSession, this.generator, 39 cast(ServerSessionListener) listener, flowControl, config.getStreamIdleTimeout()); 40 http2ServerSession.setMaxLocalStreams(config.getMaxConcurrentStreams()); 41 http2ServerSession.setMaxRemoteStreams(config.getMaxConcurrentStreams()); 42 http2ServerSession.setInitialSessionRecvWindow(config.getInitialSessionRecvWindow()); 43 return http2ServerSession; 44 } 45 46 override 47 protected Parser initParser(Http2Configuration config) { 48 return new ServerParser(cast(Http2ServerSession) http2Session, config.getMaxDynamicTableSize(), config.getMaxRequestHeadLength()); 49 } 50 51 override 52 ConnectionType getConnectionType() { 53 return super.getConnectionType(); 54 } 55 56 override 57 bool isEncrypted() { 58 return super.isEncrypted(); 59 } 60 61 ServerParser getParser() { 62 return cast(ServerParser) parser; 63 } 64 65 Http2Generator getGenerator() { 66 return generator; 67 } 68 69 SessionSPI getSessionSPI() { 70 return http2Session; 71 } 72 73 override 74 void upgradeHttpTunnel(Promise!HttpTunnelConnection promise) { 75 throw new IllegalStateException("the http2 connection can not upgrade to http tunnel"); 76 } 77 78 override 79 CompletableFuture!HttpTunnelConnection upgradeHttpTunnel() { 80 throw new IllegalStateException("the http2 connection can not upgrade to http tunnel"); 81 } 82 }