Save flows to a file. If the path starts with a +, flows are appended to the file, otherwise it is over-written.
(self, flows: Sequence[flow.Flow], path: mitmproxy.types.Path)
| 131 | |
| 132 | @command.command("save.file") |
| 133 | def save(self, flows: Sequence[flow.Flow], path: mitmproxy.types.Path) -> None: |
| 134 | """ |
| 135 | Save flows to a file. If the path starts with a +, flows are |
| 136 | appended to the file, otherwise it is over-written. |
| 137 | """ |
| 138 | try: |
| 139 | with open(_path(path), _mode(path)) as f: |
| 140 | stream = io.FlowWriter(f) |
| 141 | for i in flows: |
| 142 | stream.add(i) |
| 143 | except OSError as e: |
| 144 | raise exceptions.CommandError(e) from e |
| 145 | if path.endswith(".har") or path.endswith(".zhar"): # pragma: no cover |
| 146 | logging.log( |
| 147 | ALERT, |
| 148 | f"Saved as mitmproxy dump file. To save HAR files, use the `save.har` command.", |
| 149 | ) |
| 150 | else: |
| 151 | logging.log(ALERT, f"Saved {len(flows)} flows.") |
| 152 | |
| 153 | def tcp_start(self, flow: tcp.TCPFlow): |
| 154 | if self.stream: |