1 module hunt.http.codec.http.stream.AbstractHttpConnection; 2 3 import hunt.http.codec.http.stream.HttpConnection; 4 5 import hunt.http.codec.http.model.HttpVersion; 6 7 import hunt.net.AbstractConnection; 8 import hunt.net.ConnectionEvent; 9 import hunt.net.secure.SecureSession; 10 import hunt.net.Session; 11 12 import hunt.lang.common; 13 14 abstract class AbstractHttpConnection :AbstractConnection, HttpConnection { 15 16 protected HttpVersion httpVersion; 17 protected Object attachment; 18 protected ConnectionEvent!HttpConnection connectionEvent; 19 20 this(SecureSession secureSession, Session tcpSession, HttpVersion httpVersion) { 21 super(secureSession, tcpSession); 22 this.httpVersion = httpVersion; 23 connectionEvent = new ConnectionEvent!(HttpConnection)(this); 24 } 25 26 override 27 Object getAttachment() { 28 return attachment; 29 } 30 31 override 32 void setAttachment(Object attachment) { 33 this.attachment = attachment; 34 } 35 36 override 37 HttpVersion getHttpVersion() { 38 return httpVersion; 39 } 40 41 override 42 bool isEncrypted() { 43 return secureSession !is null; 44 } 45 46 override 47 HttpConnection onClose(Action1!HttpConnection closedListener) { 48 return connectionEvent.onClose(closedListener); 49 } 50 51 override 52 HttpConnection onException(Action2!(HttpConnection, Exception) exceptionListener) { 53 return connectionEvent.onException(exceptionListener); 54 } 55 56 void notifyClose() { 57 connectionEvent.notifyClose(); 58 } 59 60 void notifyException(Exception t) { 61 connectionEvent.notifyException(t); 62 } 63 }