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)
| 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]: |
nothing calls this directly
no test coverage detected