MCPcopy
hub / github.com/mitmproxy/mitmproxy / _init_transformations

Method _init_transformations

examples/contrib/jsondump.py:102–141  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

100 }
101
102 def _init_transformations(self):
103 self.transformations = [
104 {
105 "fields": self.fields["headers"],
106 "func": dict,
107 },
108 {
109 "fields": self.fields["timestamp"],
110 "func": lambda t: int(t * 1000),
111 },
112 {
113 "fields": self.fields["ip"],
114 "func": lambda addr: {
115 "host": addr[0].replace("::ffff:", ""),
116 "port": addr[1],
117 },
118 },
119 {
120 "fields": self.fields["ws_messages"],
121 "func": lambda ms: [
122 {
123 "type": m[0],
124 "from_client": m[1],
125 "content": base64.b64encode(bytes(m[2], "utf-8"))
126 if self.encode
127 else m[2],
128 "timestamp": int(m[3] * 1000),
129 }
130 for m in ms
131 ],
132 },
133 ]
134
135 if self.encode:
136 self.transformations.append(
137 {
138 "fields": self.fields["content"],
139 "func": base64.b64encode,
140 }
141 )
142
143 @staticmethod
144 def transform_field(obj, path, func):

Callers 1

configureMethod · 0.95

Calls 2

replaceMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected