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.codec.http.stream.AbstractHttpConnection; 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.Http2Configuration; 13 import hunt.http.codec.http.stream.Session; 14 import hunt.http.codec.http.stream.SimpleFlowControlStrategy; 15 16 import hunt.net.ConnectionType; 17 import hunt.net.secure.SecureSession; 18 import hunt.net.Session; 19 20 import hunt.lang.exception; 21 22 // alias TcpSession = hunt.net.Session.Session; 23 alias Listener = hunt.http.codec.http.stream.Session.Session.Listener; 24 25 abstract class AbstractHttp2Connection :AbstractHttpConnection { 26 27 protected Http2Session http2Session; 28 protected Parser parser; 29 protected Http2Generator generator; 30 31 this(Http2Configuration config,TcpSession tcpSession, 32 SecureSession secureSession, Listener listener) { 33 34 super(secureSession, 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 ConnectionType getConnectionType() { 55 return ConnectionType.HTTP2; 56 } 57 58 abstract protected Http2Session initHttp2Session(Http2Configuration config, FlowControlStrategy flowControl, 59 Listener listener); 60 61 abstract protected Parser initParser(Http2Configuration config); 62 63 StreamSession getHttp2Session() { 64 return http2Session; 65 } 66 67 }