1 module hunt.http.codec.websocket.model.extension.identity.IdentityExtension; 2 3 import hunt.http.WebSocketFrame; 4 import hunt.http.codec.websocket.model.ExtensionConfig; 5 import hunt.http.codec.websocket.model.extension.AbstractExtension; 6 7 // import hunt.http.utils.lang.QuotedStringTokenizer; 8 9 import hunt.Exceptions; 10 import hunt.util.Common; 11 import hunt.text.Common; 12 import hunt.text.QuotedStringTokenizer; 13 import hunt.util.StringBuilder; 14 15 import std.conv; 16 17 /** 18 */ 19 class IdentityExtension : AbstractExtension { 20 private string id; 21 22 this() { 23 start(); 24 } 25 26 string getParam(string key) { 27 return getConfig().getParameter(key, "?"); 28 } 29 30 override string getName() { 31 return "identity"; 32 } 33 34 override void incomingError(Exception e) { 35 // pass through 36 nextIncomingError(e); 37 } 38 39 // override 40 void incomingFrame(WebSocketFrame frame) { 41 // pass through 42 nextIncomingFrame(frame); 43 } 44 45 // override 46 void outgoingFrame(WebSocketFrame frame, Callback callback) { 47 // pass through 48 nextOutgoingFrame(frame, callback); 49 } 50 51 override void setConfig(ExtensionConfig config) { 52 super.setConfig(config); 53 StringBuilder s = new StringBuilder(); 54 s.append(config.getName()); 55 s.append("@").append(to!string(toHash(), 16)); 56 // s.append("@").append(Integer.toHexString(hashCode())); 57 s.append("["); 58 bool delim = false; 59 foreach (string param; config.getParameterKeys()) { 60 if (delim) { 61 s.append(';'); 62 } 63 string str = QuotedStringTokenizer.quoteIfNeeded(config.getParameter(param, ""), ";="); 64 s.append(param).append('=').append(str); 65 delim = true; 66 } 67 s.append("]"); 68 id = s.toString(); 69 } 70 71 override string toString() { 72 return id; 73 } 74 75 override protected void initialize() { 76 77 } 78 79 override protected void destroy() { 80 81 } 82 }