aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2016-07-08 19:57:57 -0700
committerMaximilian Hils <git@maximilianhils.com>2016-07-08 19:57:57 -0700
commit5d2b7c52f9c33e84be5c4330b09b0f2a5ad869e2 (patch)
tree01d2f83583f0a47706def85b9ed82ed045d5f4b6 /examples
parent7c67faa8da39f428d1860bccae806137943b66a6 (diff)
downloadmitmproxy-5d2b7c52f9c33e84be5c4330b09b0f2a5ad869e2.tar.gz
mitmproxy-5d2b7c52f9c33e84be5c4330b09b0f2a5ad869e2.tar.bz2
mitmproxy-5d2b7c52f9c33e84be5c4330b09b0f2a5ad869e2.zip
move script context to mitmproxy.ctx
Diffstat (limited to 'examples')
-rw-r--r--examples/har_extractor.py6
-rw-r--r--examples/nonblocking.py4
-rw-r--r--examples/proxapp.py4
-rw-r--r--examples/stub.py20
-rw-r--r--examples/tls_passthrough.py2
5 files changed, 18 insertions, 18 deletions
diff --git a/examples/har_extractor.py b/examples/har_extractor.py
index 208a2fa8..2a69b9af 100644
--- a/examples/har_extractor.py
+++ b/examples/har_extractor.py
@@ -219,17 +219,17 @@ def done():
compressed_json_dump = context.HARLog.compress()
if context.dump_file == '-':
- mitmproxy.log(pprint.pformat(json.loads(json_dump)))
+ mitmproxy.ctx.log(pprint.pformat(json.loads(json_dump)))
elif context.dump_file.endswith('.zhar'):
file(context.dump_file, "w").write(compressed_json_dump)
else:
file(context.dump_file, "w").write(json_dump)
- mitmproxy.log(
+ mitmproxy.ctx.log(
"HAR log finished with %s bytes (%s bytes compressed)" % (
len(json_dump), len(compressed_json_dump)
)
)
- mitmproxy.log(
+ mitmproxy.ctx.log(
"Compression rate is %s%%" % str(
100. * len(compressed_json_dump) / len(json_dump)
)
diff --git a/examples/nonblocking.py b/examples/nonblocking.py
index 05a26921..b81478df 100644
--- a/examples/nonblocking.py
+++ b/examples/nonblocking.py
@@ -5,6 +5,6 @@ from mitmproxy.script import concurrent
@concurrent # Remove this and see what happens
def request(flow):
- mitmproxy.log("handle request: %s%s" % (flow.request.host, flow.request.path))
+ mitmproxy.ctx.log("handle request: %s%s" % (flow.request.host, flow.request.path))
time.sleep(5)
- mitmproxy.log("start request: %s%s" % (flow.request.host, flow.request.path))
+ mitmproxy.ctx.log("start request: %s%s" % (flow.request.host, flow.request.path))
diff --git a/examples/proxapp.py b/examples/proxapp.py
index ddc38544..2935b587 100644
--- a/examples/proxapp.py
+++ b/examples/proxapp.py
@@ -17,9 +17,9 @@ def hello_world():
# Register the app using the magic domain "proxapp" on port 80. Requests to
# this domain and port combination will now be routed to the WSGI app instance.
def start():
- mitmproxy.master.apps.add(app, "proxapp", 80)
+ mitmproxy.ctx.master.apps.add(app, "proxapp", 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.master.apps.add(app, "example.com", 443)
+ mitmproxy.ctx.master.apps.add(app, "example.com", 443)
diff --git a/examples/stub.py b/examples/stub.py
index a4f16699..10b34283 100644
--- a/examples/stub.py
+++ b/examples/stub.py
@@ -8,7 +8,7 @@ def start():
"""
Called once on script startup, before any other events.
"""
- mitmproxy.log("start")
+ mitmproxy.ctx.log("start")
def clientconnect(root_layer):
@@ -16,14 +16,14 @@ def clientconnect(root_layer):
Called when a client initiates a connection to the proxy. Note that a
connection can correspond to multiple HTTP requests
"""
- mitmproxy.log("clientconnect")
+ mitmproxy.ctx.log("clientconnect")
def request(flow):
"""
Called when a client request has been received.
"""
- mitmproxy.log("request")
+ mitmproxy.ctx.log("request")
def serverconnect(server_conn):
@@ -31,7 +31,7 @@ def serverconnect(server_conn):
Called when the proxy initiates a connection to the target server. Note that a
connection can correspond to multiple HTTP requests
"""
- mitmproxy.log("serverconnect")
+ mitmproxy.ctx.log("serverconnect")
def responseheaders(flow):
@@ -40,14 +40,14 @@ def responseheaders(flow):
but the response body has not been processed yet. Can be used to tell mitmproxy
to stream the response.
"""
- mitmproxy.log("responseheaders")
+ mitmproxy.ctx.log("responseheaders")
def response(flow):
"""
Called when a server response has been received.
"""
- mitmproxy.log("response")
+ mitmproxy.ctx.log("response")
def error(flow):
@@ -56,25 +56,25 @@ def error(flow):
interrupted connections. This is distinct from a valid server HTTP error
response, which is simply a response with an HTTP error code.
"""
- mitmproxy.log("error")
+ mitmproxy.ctx.log("error")
def serverdisconnect(server_conn):
"""
Called when the proxy closes the connection to the target server.
"""
- mitmproxy.log("serverdisconnect")
+ mitmproxy.ctx.log("serverdisconnect")
def clientdisconnect(root_layer):
"""
Called when a client disconnects from the proxy.
"""
- mitmproxy.log("clientdisconnect")
+ mitmproxy.ctx.log("clientdisconnect")
def done():
"""
Called once on script shutdown, after any other events.
"""
- mitmproxy.log("done")
+ mitmproxy.ctx.log("done")
diff --git a/examples/tls_passthrough.py b/examples/tls_passthrough.py
index 374020e7..20e8f9be 100644
--- a/examples/tls_passthrough.py
+++ b/examples/tls_passthrough.py
@@ -135,7 +135,7 @@ def next_layer(next_layer):
next_layer.__class__ = TlsFeedback
else:
# We don't intercept - reply with a pass-through layer and add a "skipped" entry.
- mitmproxy.log("TLS passthrough for %s" % repr(next_layer.server_conn.address), "info")
+ mitmproxy.ctx.log("TLS passthrough for %s" % repr(next_layer.server_conn.address), "info")
next_layer_replacement = RawTCPLayer(next_layer.ctx, ignore=True)
next_layer.reply.send(next_layer_replacement)
tls_strategy.record_skipped(server_address)