Export flows to an HAR (HTTP Archive) file.
(self, flows: Sequence[flow.Flow], path: types.Path)
| 34 | |
| 35 | @command.command("save.har") |
| 36 | def export_har(self, flows: Sequence[flow.Flow], path: types.Path) -> None: |
| 37 | """Export flows to an HAR (HTTP Archive) file.""" |
| 38 | |
| 39 | har = json.dumps(self.make_har(flows), indent=4).encode() |
| 40 | |
| 41 | if path.endswith(".zhar"): |
| 42 | har = zlib.compress(har, 9) |
| 43 | |
| 44 | with open(path, "wb") as f: |
| 45 | f.write(har) |
| 46 | |
| 47 | logging.log(ALERT, f"HAR file saved ({human.pretty_size(len(har))} bytes).") |
| 48 | |
| 49 | def make_har(self, flows: Sequence[flow.Flow]) -> dict: |
| 50 | entries = [] |