MCPcopy
hub / github.com/mitmproxy/mitmproxy / bodyview

Method bodyview

mitmproxy/tools/console/consoleaddons.py:369–385  ·  view source on GitHub ↗

Spawn an external viewer for a flow request or response body based on the detected MIME type. We use the mailcap system to find the correct viewer, and fall back to the programs in $PAGER or $EDITOR if necessary.

(self, flow: flow.Flow, part: str)

Source from the content-addressed store, hash-verified

367 @command.command("console.bodyview")
368 @command.argument("part", type=mitmproxy.types.Choice("console.bodyview.options"))
369 def bodyview(self, flow: flow.Flow, part: str) -> None:
370 """
371 Spawn an external viewer for a flow request or response body based
372 on the detected MIME type. We use the mailcap system to find the
373 correct viewer, and fall back to the programs in $PAGER or $EDITOR
374 if necessary.
375 """
376 fpart = getattr(flow, part, None)
377 if not fpart:
378 raise exceptions.CommandError(
379 "Part must be either request or response, not %s." % part
380 )
381 t = fpart.headers.get("content-type")
382 content = fpart.get_content(strict=False)
383 if not content:
384 raise exceptions.CommandError("No content to view.")
385 self.master.spawn_external_viewer(content, t)
386
387 @command.command("console.bodyview.options")
388 def bodyview_options(self) -> Sequence[str]:

Callers

nothing calls this directly

Calls 3

get_contentMethod · 0.80
spawn_external_viewerMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected