@@ -68,6 +68,8 @@ def __init__(self,
6868 self .last_message_ctx = {}
6969 self .request_counter = 0
7070
71+ self ._queue_response_req_message = Queue ()
72+
7173 # Properties
7274
7375 @property
@@ -133,9 +135,12 @@ def send_custom_message(self, message: Union[str, bytes]) -> None:
133135 if not isinstance (message , bytes ):
134136 message = message .encode ()
135137
136- self .custom_message = message
138+ with self ._queue_response_req_message .mutex :
139+ self ._queue_response_req_message .queue .clear ()
137140 self .custom_message_sent = False
138141
142+ self .custom_message = message
143+
139144 # Internal methods.
140145
141146 def __remoted_response_simulation (self , request : Any ) -> bytes :
@@ -176,9 +181,13 @@ def __remoted_response_simulation(self, request: Any) -> bytes:
176181 elif '#!-agent shutdown' in message :
177182 self .__mitm .event .set ()
178183 response = _RESPONSE_SHUTDOWN
184+ elif '#!-req' in message :
185+ self ._queue_response_req_message .put (message )
186+ response = _RESPONSE_EMPTY
179187 elif self .custom_message and not self .custom_message_sent :
180188 response = self .custom_message
181189 self .custom_message_sent = True
190+ self .custom_message = None
182191 elif '#!-' in message :
183192 response = _RESPONSE_ACK
184193 else :
0 commit comments