Replies: 2 comments 2 replies
-
Through dir(flow), I found that there is a client_conn method, which temporarily solved the problem. I don't know if there is a better way to make the data persistent. from multiprocessing import Lock
class func:
def __init__(self):
self.mutex = Lock()
self.meta = {}
pass
def set_kv(self, dev, info):
self.meta[dev] = info
return
def get_kv(self, dev):
ret = self.meta[dev]
return ret
def request(self, flow: mitmproxy.http.HTTPFlow):
url = flow.request.url
if 'xxx' in url:
self.mutex.acquire()
dev = flow.client_conn.peername[0]
var_get_from_url = "url...."
self.set_kv(dev, var_get_from_url)
self.mutex.release()
if 'yyy' in url:
self.mutex.acquire()
dev = flow.client_conn.peername[0]
var_get_from_url = "url...."
func(self.get_kv(dev))
self.mutex.release()
return |
Beta Was this translation helpful? Give feedback.
-
Without the The way you are currently using the mutex doesn't make sense. There is a single instance of your Each connection has a unique |
Beta Was this translation helpful? Give feedback.
-
Hi, everyone:
I want to maintain a variable between multiple connections of a device, because there will be multiple devices and multiple connections, so the variables of multiple devices cannot be overwritten with each other.
I don't know if there is a function similar to "object-oriented programming", every device gets an instance.
I am currently trying to implement it with mutex lock, but I don't know how to get the device's information the connection come from.
There is still a problem here, that is, getting the device info from client_connected , and setting value for the device. not a
atomic operation .
It would be nice if the connected device information could be obtained directly from the request event.
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions