From a17a53269d23d0bde74c340c9df4b1983b70144b Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 15 May 2014 14:37:05 +0200 Subject: [PATCH] fix #253 --- examples/{read_dumpfile.py => read_dumpfile} | 0 examples/redirect_requests.py | 13 ++++++------- test/test_examples.py | 12 ++++++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) rename examples/{read_dumpfile.py => read_dumpfile} (100%) create mode 100644 test/test_examples.py diff --git a/examples/read_dumpfile.py b/examples/read_dumpfile similarity index 100% rename from examples/read_dumpfile.py rename to examples/read_dumpfile diff --git a/examples/redirect_requests.py b/examples/redirect_requests.py index 3a3ad300f..278160c72 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" diff --git a/test/test_examples.py b/test/test_examples.py new file mode 100644 index 000000000..014b1d68f --- /dev/null +++ b/test/test_examples.py @@ -0,0 +1,12 @@ +from libmproxy import utils, script +import glob +from libmproxy.proxy import config +import tservers + +example_dir = utils.Data("libmproxy").path("../examples/") +scripts = glob.glob("%s*.py" % example_dir) + +tmaster = tservers.TestMaster(config.ProxyConfig()) + +for f in scripts: + script.Script(f, tmaster) # Loads the script file. \ No newline at end of file