From b4f49d018697e6349ad7b86c58aadc42f77d31b7 Mon Sep 17 00:00:00 2001 From: Daniel Karandikar Date: Wed, 6 Mar 2024 21:18:43 +0000 Subject: [PATCH] Update io-write-flow-file.py example with option (#6464) #### Description Update example addon as described in https://github.com/mitmproxy/mitmproxy/issues/6445 #### Checklist - [x] I have updated tests where applicable. --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Maximilian Hils --- examples/addons/io-write-flow-file.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/addons/io-write-flow-file.py b/examples/addons/io-write-flow-file.py index d956d5f85..76fcbb46e 100644 --- a/examples/addons/io-write-flow-file.py +++ b/examples/addons/io-write-flow-file.py @@ -8,8 +8,8 @@ flows should be saved and also allows you to rotate files or log to multiple files in parallel. """ +import os import random -import sys from typing import BinaryIO from mitmproxy import http @@ -17,8 +17,11 @@ from mitmproxy import io class Writer: - def __init__(self, path: str) -> None: - self.f: BinaryIO = open(path, "wb") + def __init__(self) -> None: + # We are using an environment variable to keep the example as simple as possible, + # consider implementing this as a mitmproxy option instead. + filename = os.getenv("MITMPROXY_OUTFILE", "out.mitm") + self.f: BinaryIO = open(filename, "wb") self.w = io.FlowWriter(self.f) def response(self, flow: http.HTTPFlow) -> None: @@ -29,4 +32,4 @@ class Writer: self.f.close() -addons = [Writer(sys.argv[1])] +addons = [Writer()]