1 module hunt.imf.protocol.http.HttpProtocol; 2 3 import hunt.imf.protocol.Protocol; 4 import hunt.net.codec.Codec; 5 import hunt.imf.ConnectionEventBaseHandler; 6 import hunt.imf.protocol.http.HttpConnectionEventHandler; 7 import hunt.imf.protocol.http.HttpCodec; 8 import hunt.imf.GatewayApplication; 9 import hunt.net.NetServerOptions; 10 import hunt.imf.ConnectionManager; 11 import hunt.net; 12 13 class HttpProtocol : Protocol 14 { 15 private { 16 string _host; 17 ushort _port; 18 enum string _name = typeof(this).stringof; 19 ConnectionEventBaseHandler _handler; 20 NetServerOptions _options = null; 21 Codec _codec; 22 } 23 24 this(string host , ushort port) 25 { 26 _host = host; 27 _port = port; 28 _handler = new HttpConnectionEventHandler(); 29 _codec = new HttpCodec(); 30 } 31 32 override void registerHandler() 33 { 34 GatewayApplication.instance().registerConnectionManager(_name); 35 ConnectionManager!int manager = GatewayApplication.instance().getConnectionManager(_name); 36 _handler.setOnConnection(&manager.onConnection); 37 } 38 39 void setCodec(Codec codec) { 40 _codec = codec; 41 } 42 43 void setConnectionEventHandler(ConnectionEventBaseHandler handler) 44 { 45 _handler = handler; 46 } 47 48 override NetServerOptions getOptions() 49 { 50 return _options; 51 } 52 53 override string getName() {return _name;} 54 55 override ushort getPort() {return _port;} 56 57 override ConnectionEventHandler getHandler() {return _handler;} 58 59 override Codec getCodec() {return _codec;} 60 61 override string getHost() {return _host;} 62 }