aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2014-09-05 15:16:20 +0200
committerMaximilian Hils <git@maximilianhils.com>2014-09-05 15:16:20 +0200
commit2a6337343a14f7f72c28d8bf5f24220f6d9ca6d0 (patch)
tree755d8cf7f6578c9346e9f3c68604615177cf9332 /examples
parentf2570c773aa18e4ac236b1cf7f43acfb4ca080dd (diff)
downloadmitmproxy-2a6337343a14f7f72c28d8bf5f24220f6d9ca6d0.tar.gz
mitmproxy-2a6337343a14f7f72c28d8bf5f24220f6d9ca6d0.tar.bz2
mitmproxy-2a6337343a14f7f72c28d8bf5f24220f6d9ca6d0.zip
update docs, mostly revert 2f44b26b4cd014e03dd62a125d79af9b81663a93
Diffstat (limited to 'examples')
-rw-r--r--examples/add_header.py4
-rw-r--r--examples/dup_and_replay.py6
-rwxr-xr-xexamples/flowbasic9
-rw-r--r--examples/modify_form.py10
-rw-r--r--examples/modify_querystring.py7
-rw-r--r--examples/nonblocking.py3
-rw-r--r--examples/redirect_requests.py4
-rwxr-xr-xexamples/stickycookies8
-rw-r--r--examples/stub.py6
-rw-r--r--examples/upsidedownternet.py2
10 files changed, 32 insertions, 27 deletions
diff --git a/examples/add_header.py b/examples/add_header.py
index 0c0593d1..b9c8c1c6 100644
--- a/examples/add_header.py
+++ b/examples/add_header.py
@@ -1,2 +1,2 @@
-def response(context, flow):
- flow.response.headers["newheader"] = ["foo"]
+def response(ctx, flow):
+ flow.response.headers["newheader"] = ["foo"] \ No newline at end of file
diff --git a/examples/dup_and_replay.py b/examples/dup_and_replay.py
index 9c58d3a4..b38c2b7e 100644
--- a/examples/dup_and_replay.py
+++ b/examples/dup_and_replay.py
@@ -1,4 +1,4 @@
def request(ctx, flow):
- f = ctx.duplicate_flow(flow)
- f.request.path = "/changed"
- ctx.replay_request(f)
+ f = ctx.duplicate_flow(flow)
+ f.request.path = "/changed"
+ ctx.replay_request(f) \ No newline at end of file
diff --git a/examples/flowbasic b/examples/flowbasic
index 8dbe2f28..2b44be3f 100755
--- a/examples/flowbasic
+++ b/examples/flowbasic
@@ -3,11 +3,14 @@
This example shows how to build a proxy based on mitmproxy's Flow
primitives.
+ Heads Up: In the majority of cases, you want to use inline scripts.
+
Note that request and response messages are not automatically replied to,
so we need to implement handlers to do this.
"""
import os
-from libmproxy import proxy, flow
+from libmproxy import flow, proxy
+from libmproxy.proxy.server import ProxyServer
class MyMaster(flow.FlowMaster):
def run(self):
@@ -31,9 +34,9 @@ class MyMaster(flow.FlowMaster):
config = proxy.ProxyConfig(
- cacert = os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem")
+ ca_file = os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem")
)
state = flow.State()
-server = proxy.ProxyServer(config, 8080)
+server = ProxyServer(config, 8080)
m = MyMaster(server, state)
m.run()
diff --git a/examples/modify_form.py b/examples/modify_form.py
index cb12ee0f..6d651b19 100644
--- a/examples/modify_form.py
+++ b/examples/modify_form.py
@@ -1,8 +1,6 @@
-def request(context, flow):
+def request(ctx, flow):
if "application/x-www-form-urlencoded" in flow.request.headers["content-type"]:
- frm = flow.request.form_urlencoded
- frm["mitmproxy"] = ["rocks"]
- flow.request.form_urlencoded = frm
-
-
+ form = flow.request.get_form_urlencoded()
+ form["mitmproxy"] = ["rocks"]
+ flow.request.set_form_urlencoded(form) \ No newline at end of file
diff --git a/examples/modify_querystring.py b/examples/modify_querystring.py
index 7e3a068a..56fbbb32 100644
--- a/examples/modify_querystring.py
+++ b/examples/modify_querystring.py
@@ -1,7 +1,6 @@
-def request(context, flow):
- q = flow.request.query
+def request(ctx, flow):
+ q = flow.request.get_query()
if q:
q["mitmproxy"] = ["rocks"]
- flow.request.query = q
-
+ flow.request.set_query(q) \ No newline at end of file
diff --git a/examples/nonblocking.py b/examples/nonblocking.py
index 9a131b32..1396742a 100644
--- a/examples/nonblocking.py
+++ b/examples/nonblocking.py
@@ -1,8 +1,9 @@
import time
from libmproxy.script import concurrent
+
@concurrent
def request(context, flow):
print "handle request: %s%s" % (flow.request.host, flow.request.path)
time.sleep(5)
- print "start request: %s%s" % (flow.request.host, flow.request.path)
+ print "start request: %s%s" % (flow.request.host, flow.request.path) \ No newline at end of file
diff --git a/examples/redirect_requests.py b/examples/redirect_requests.py
index cc642039..c5561839 100644
--- a/examples/redirect_requests.py
+++ b/examples/redirect_requests.py
@@ -6,7 +6,9 @@ This example shows two ways to redirect flows to other destinations.
"""
-def request(context, flow):
+def request(ctx, flow):
+ # pretty_host(hostheader=True) takes the Host: header of the request into account,
+ # which is useful in transparent mode where we usually only have the IP otherwise.
if flow.request.pretty_host(hostheader=True).endswith("example.com"):
resp = HTTPResponse(
[1, 1], 200, "OK",
diff --git a/examples/stickycookies b/examples/stickycookies
index 17cd6019..2aab31d6 100755
--- a/examples/stickycookies
+++ b/examples/stickycookies
@@ -5,8 +5,10 @@ implement functionality similar to the "sticky cookies" option. This is at
a lower level than the Flow mechanism, so we're dealing directly with
request and response objects.
"""
-from libmproxy import controller, proxy
import os
+from libmproxy import controller, proxy
+from libmproxy.proxy.server import ProxyServer
+
class StickyMaster(controller.Master):
def __init__(self, server):
@@ -35,8 +37,8 @@ class StickyMaster(controller.Master):
config = proxy.ProxyConfig(
- cacert = os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem")
+ ca_file = os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem")
)
-server = proxy.ProxyServer(config, 8080)
+server = ProxyServer(config, 8080)
m = StickyMaster(server)
m.run()
diff --git a/examples/stub.py b/examples/stub.py
index 0cf67db7..5976dd76 100644
--- a/examples/stub.py
+++ b/examples/stub.py
@@ -7,14 +7,14 @@ def start(ctx, argv):
"""
ctx.log("start")
-def clientconnect(ctx, client_connect):
+def clientconnect(ctx, conn_handler):
"""
Called when a client initiates a connection to the proxy. Note that a
connection can correspond to multiple HTTP requests
"""
ctx.log("clientconnect")
-def serverconnect(ctx, server_connection):
+def serverconnect(ctx, conn_handler):
"""
Called when the proxy initiates a connection to the target server. Note that a
connection can correspond to multiple HTTP requests
@@ -50,7 +50,7 @@ def error(ctx, flow):
"""
ctx.log("error")
-def clientdisconnect(ctx, client_disconnect):
+def clientdisconnect(ctx, conn_handler):
"""
Called when a client disconnects from the proxy.
"""
diff --git a/examples/upsidedownternet.py b/examples/upsidedownternet.py
index 181a40c2..a52b6d30 100644
--- a/examples/upsidedownternet.py
+++ b/examples/upsidedownternet.py
@@ -1,7 +1,7 @@
import cStringIO
from PIL import Image
-def response(context, flow):
+def response(ctx, flow):
if flow.response.headers["content-type"] == ["image/png"]:
s = cStringIO.StringIO(flow.response.content)
img = Image.open(s).rotate(180)