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