From d573d4e5d744f823890695cf324b02c324984098 Mon Sep 17 00:00:00 2001 From: beth92 Date: Mon, 20 Jan 2020 13:25:30 -0500 Subject: Update WSGI example --- examples/simple/wsgi_flask_app.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'examples/simple') diff --git a/examples/simple/wsgi_flask_app.py b/examples/simple/wsgi_flask_app.py index 4be38000..cdbd750c 100644 --- a/examples/simple/wsgi_flask_app.py +++ b/examples/simple/wsgi_flask_app.py @@ -13,13 +13,13 @@ app = Flask("proxapp") def hello_world() -> str: return 'Hello World!' - -def load(l): +addons = [ # Host app at the magic domain "proxapp.local" on port 80. Requests to this # domain and port combination will now be routed to the WSGI app instance. - return wsgiapp.WSGIApp(app, "proxapp.local", 80) - + wsgiapp.WSGIApp(app, "proxapp.local", 80) + # SSL works too, but the magic domain needs to be resolvable from the mitmproxy machine due to mitmproxy's design. # mitmproxy will connect to said domain and use serve its certificate (unless --no-upstream-cert is set) # but won't send any data. # mitmproxy.ctx.master.apps.add(app, "example.com", 443) +] -- cgit v1.2.3 From f5b76d6230d0e2a123b362348552b38ae463a8ca Mon Sep 17 00:00:00 2001 From: beth Date: Mon, 20 Jan 2020 13:47:14 -0500 Subject: Address lint --- examples/simple/wsgi_flask_app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/simple') diff --git a/examples/simple/wsgi_flask_app.py b/examples/simple/wsgi_flask_app.py index cdbd750c..bbde6913 100644 --- a/examples/simple/wsgi_flask_app.py +++ b/examples/simple/wsgi_flask_app.py @@ -13,11 +13,11 @@ app = Flask("proxapp") def hello_world() -> str: return 'Hello World!' + addons = [ # Host app at the magic domain "proxapp.local" on port 80. Requests to this # domain and port combination will now be routed to the WSGI app instance. - wsgiapp.WSGIApp(app, "proxapp.local", 80) - + wsgiapp.WSGIApp(app, "proxapp.local", 80) # SSL works too, but the magic domain needs to be resolvable from the mitmproxy machine due to mitmproxy's design. # mitmproxy will connect to said domain and use serve its certificate (unless --no-upstream-cert is set) # but won't send any data. -- cgit v1.2.3 From 678be7a052007e26939b5f0cfa13200ab032cf86 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Sat, 4 Apr 2020 15:31:38 +0200 Subject: improve scripting docs --- examples/simple/websocket_messages.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'examples/simple') diff --git a/examples/simple/websocket_messages.py b/examples/simple/websocket_messages.py index 719e7b10..071ea21f 100644 --- a/examples/simple/websocket_messages.py +++ b/examples/simple/websocket_messages.py @@ -6,8 +6,15 @@ def websocket_message(flow): # get the latest message message = flow.messages[-1] - # simply print the content of the message - ctx.log.info(message.content) + # was the message sent from the client or server? + if message.from_client: + ctx.log.info("Client sent a message: {}".format(message.content)) + else: + ctx.log.info("Server sent a message: {}".format(message.content)) # manipulate the message content message.content = re.sub(r'^Hello', 'HAPPY', message.content) + + if 'FOOBAR' in message.content: + # kill the message and not send it to the other endpoint + message.kill() -- cgit v1.2.3