MCPcopy
hub / github.com/mitmproxy/mitmproxy / _ask

Method _ask

mitmproxy/proxy/layer.py:291–314  ·  view source on GitHub ↗

Manually trigger a next_layer hook. The only use at the moment is to make sure that the top layer is initialized.

(self)

Source from the content-addressed store, hash-verified

289 yield from self._ask()
290
291 def _ask(self):
292 """
293 Manually trigger a next_layer hook.
294 The only use at the moment is to make sure that the top layer is initialized.
295 """
296 yield NextLayerHook(self)
297
298 # Has an addon decided on the next layer yet?
299 if self.layer:
300 if self.debug:
301 yield commands.Log(f"{self.debug}[nextlayer] {self.layer!r}", DEBUG)
302 for e in self.events:
303 yield from self.layer.handle_event(e)
304 self.events.clear()
305
306 # Why do we need three assignments here?
307 # 1. When this function here is invoked we may have paused events. Those should be
308 # forwarded to the sublayer right away, so we reassign ._handle_event.
309 # 2. This layer is not needed anymore, so we directly reassign .handle_event.
310 # 3. Some layers may however still have a reference to the old .handle_event.
311 # ._handle is just an optimization to reduce the callstack in these cases.
312 self.handle_event = self.layer.handle_event # type: ignore
313 self._handle_event = self.layer.handle_event # type: ignore
314 self._handle = self.layer.handle_event
315
316 # Utility methods for whoever decides what the next layer is going to be.
317 def data_client(self):

Callers 1

_handle_eventMethod · 0.95

Calls 3

NextLayerHookClass · 0.85
handle_eventMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected