diff --git a/examples/flowbasic b/examples/flowbasic index 6663dc468..78b9eff70 100755 --- a/examples/flowbasic +++ b/examples/flowbasic @@ -8,9 +8,8 @@ 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 flow, proxy -from libmproxy.proxy.server import ProxyServer +from libmproxy import flow +from libmproxy.proxy import ProxyServer, ProxyConfig class MyMaster(flow.FlowMaster): @@ -34,7 +33,7 @@ class MyMaster(flow.FlowMaster): return f -config = proxy.ProxyConfig( +config = ProxyConfig( port=8080, # use ~/.mitmproxy/mitmproxy-ca.pem as default CA file. cadir="~/.mitmproxy/" diff --git a/examples/iframe_injector.py b/examples/iframe_injector.py index b2fa2d26f..29de9b63f 100644 --- a/examples/iframe_injector.py +++ b/examples/iframe_injector.py @@ -1,7 +1,7 @@ # Usage: mitmdump -s "iframe_injector.py url" # (this script works best with --anticache) from bs4 import BeautifulSoup -from libmproxy.protocol.http import decoded +from libmproxy.models import decoded def start(context, argv): diff --git a/examples/modify_form.py b/examples/modify_form.py index 37ba2faca..c2f0a47e5 100644 --- a/examples/modify_form.py +++ b/examples/modify_form.py @@ -1,7 +1,5 @@ - def request(context, flow): - if "application/x-www-form-urlencoded" in flow.request.headers[ - "content-type"]: + if "application/x-www-form-urlencoded" in flow.request.headers["content-type"]: form = flow.request.get_form_urlencoded() form["mitmproxy"] = ["rocks"] flow.request.set_form_urlencoded(form) diff --git a/examples/modify_response_body.py b/examples/modify_response_body.py index 68d3d4abd..a35e1525f 100644 --- a/examples/modify_response_body.py +++ b/examples/modify_response_body.py @@ -1,6 +1,6 @@ # Usage: mitmdump -s "modify_response_body.py mitmproxy bananas" # (this script works best with --anticache) -from libmproxy.protocol.http import decoded +from libmproxy.models import decoded def start(context, argv): diff --git a/examples/read_dumpfile b/examples/read_dumpfile index eb1c93bbf..b329c0e1b 100755 --- a/examples/read_dumpfile +++ b/examples/read_dumpfile @@ -4,7 +4,6 @@ # from libmproxy import flow -import json import pprint import sys diff --git a/examples/redirect_requests.py b/examples/redirect_requests.py index 48512f1bb..2ae4927bf 100644 --- a/examples/redirect_requests.py +++ b/examples/redirect_requests.py @@ -1,9 +1,8 @@ -from libmproxy.protocol.http import HTTPResponse -from netlib.odict import ODictCaseless - """ This example shows two ways to redirect flows to other destinations. """ +from libmproxy.models import HTTPResponse +from netlib.odict import ODictCaseless def request(context, flow): diff --git a/examples/stream_modify.py b/examples/stream_modify.py index e3f1f3cf7..aa395c03f 100644 --- a/examples/stream_modify.py +++ b/examples/stream_modify.py @@ -11,11 +11,9 @@ Be aware that content replacement isn't trivial: def modify(chunks): """ chunks is a generator that can be used to iterate over all chunks. - Each chunk is a (prefix, content, suffix) tuple. - For example, in the case of chunked transfer encoding: ("3\r\n","foo","\r\n") """ - for prefix, content, suffix in chunks: - yield prefix, content.replace("foo", "bar"), suffix + for chunk in chunks: + yield chunk.replace("foo", "bar") def responseheaders(context, flow): diff --git a/examples/stub.py b/examples/stub.py index bd3e7cd02..516b71a53 100644 --- a/examples/stub.py +++ b/examples/stub.py @@ -18,14 +18,6 @@ def clientconnect(context, root_layer): context.log("clientconnect") -def serverconnect(context, server_connection): - """ - Called when the proxy initiates a connection to the target server. Note that a - connection can correspond to multiple HTTP requests - """ - context.log("serverconnect") - - def request(context, flow): """ Called when a client request has been received. @@ -33,6 +25,14 @@ def request(context, flow): context.log("request") +def serverconnect(context, server_conn): + """ + Called when the proxy initiates a connection to the target server. Note that a + connection can correspond to multiple HTTP requests + """ + context.log("serverconnect") + + def responseheaders(context, flow): """ Called when the response headers for a server response have been received, @@ -58,7 +58,7 @@ def error(context, flow): context.log("error") -def serverdisconnect(context, server_connection): +def serverdisconnect(context, server_conn): """ Called when the proxy closes the connection to the target server. """ diff --git a/examples/upsidedownternet.py b/examples/upsidedownternet.py index a6de97e4c..e8444c839 100644 --- a/examples/upsidedownternet.py +++ b/examples/upsidedownternet.py @@ -1,6 +1,6 @@ import cStringIO from PIL import Image -from libmproxy.protocol.http import decoded +from libmproxy.models import decoded def response(context, flow):