update example inline scripts

This commit is contained in:
Maximilian Hils 2015-09-04 00:46:42 +02:00
parent 14457f29b3
commit a18db90ea3
9 changed files with 20 additions and 27 deletions

View File

@ -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/"

View File

@ -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):

View File

@ -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)

View File

@ -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):

View File

@ -4,7 +4,6 @@
#
from libmproxy import flow
import json
import pprint
import sys

View File

@ -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):

View File

@ -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):

View File

@ -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.
"""

View File

@ -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):