From a17a53269d23d0bde74c340c9df4b1983b70144b Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 15 May 2014 14:37:05 +0200 Subject: fix #253 --- examples/read_dumpfile | 17 +++++++++++++++++ examples/read_dumpfile.py | 17 ----------------- examples/redirect_requests.py | 13 ++++++------- 3 files changed, 23 insertions(+), 24 deletions(-) create mode 100644 examples/read_dumpfile delete mode 100644 examples/read_dumpfile.py (limited to 'examples') diff --git a/examples/read_dumpfile b/examples/read_dumpfile new file mode 100644 index 00000000..547f3c17 --- /dev/null +++ b/examples/read_dumpfile @@ -0,0 +1,17 @@ +#!/usr/bin/env python +# +# Simple script showing how to read a mitmproxy dump file +# + +from libmproxy import flow +import json, sys + +with open("logfile", "rb") as f: + freader = flow.FlowReader(f) + try: + for i in freader.stream(): + print i.request.host + json.dump(i._get_state(), sys.stdout, indent=4) + print "" + except flow.FlowReadError, v: + print "Flow file corrupted. Stopped loading." \ No newline at end of file diff --git a/examples/read_dumpfile.py b/examples/read_dumpfile.py deleted file mode 100644 index 547f3c17..00000000 --- a/examples/read_dumpfile.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env python -# -# Simple script showing how to read a mitmproxy dump file -# - -from libmproxy import flow -import json, sys - -with open("logfile", "rb") as f: - freader = flow.FlowReader(f) - try: - for i in freader.stream(): - print i.request.host - json.dump(i._get_state(), sys.stdout, indent=4) - print "" - except flow.FlowReadError, v: - print "Flow file corrupted. Stopped loading." \ No newline at end of file diff --git a/examples/redirect_requests.py b/examples/redirect_requests.py index 3a3ad300..278160c7 100644 --- a/examples/redirect_requests.py +++ b/examples/redirect_requests.py @@ -1,18 +1,17 @@ -from libmproxy.flow import Response +from libmproxy.protocol.http import HTTPResponse from netlib.odict import ODictCaseless """ This example shows two ways to redirect flows to other destinations. """ + def request(context, flow): if flow.request.host.endswith("example.com"): - resp = Response(flow.request, - [1,1], - 200, "OK", - ODictCaseless([["Content-Type","text/html"]]), - "helloworld", - None) + resp = HTTPResponse( + [1, 1], 200, "OK", + ODictCaseless([["Content-Type", "text/html"]]), + "helloworld") flow.request.reply(resp) if flow.request.host.endswith("example.org"): flow.request.host = "mitmproxy.org" -- cgit v1.2.3