| 504 | |
| 505 | class DumpFlows(RequestHandler): |
| 506 | def get(self) -> None: |
| 507 | self.set_header("Content-Disposition", "attachment; filename=flows") |
| 508 | self.set_header("Content-Type", "application/octet-stream") |
| 509 | |
| 510 | match: Callable[[mitmproxy.flow.Flow], bool] |
| 511 | try: |
| 512 | match = flowfilter.parse(self.request.arguments["filter"][0].decode()) |
| 513 | except ValueError: # thrown py flowfilter.parse if filter is invalid |
| 514 | raise APIError(400, f"Invalid filter argument / regex") |
| 515 | except ( |
| 516 | KeyError, |
| 517 | IndexError, |
| 518 | ): # Key+Index: ["filter"][0] can fail, if it's not set |
| 519 | |
| 520 | def match(_) -> bool: |
| 521 | return True |
| 522 | |
| 523 | with BytesIO() as bio: |
| 524 | fw = io.FlowWriter(bio) |
| 525 | for f in self.view: |
| 526 | if match(f): |
| 527 | fw.add(f) |
| 528 | self.write(bio.getvalue()) |
| 529 | |
| 530 | async def post(self): |
| 531 | self.view.clear() |