aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2011-08-02 16:52:47 +1200
committerAldo Cortesi <aldo@nullcube.com>2011-08-02 16:52:47 +1200
commit1ff6a767d001a8c0f45a190e26be363ea9410534 (patch)
treeca511b918637e306140be6318dab05037ed4beda /libmproxy
parent357502fe03a5f86c1c29d35c5d607541df157640 (diff)
downloadmitmproxy-1ff6a767d001a8c0f45a190e26be363ea9410534.tar.gz
mitmproxy-1ff6a767d001a8c0f45a190e26be363ea9410534.tar.bz2
mitmproxy-1ff6a767d001a8c0f45a190e26be363ea9410534.zip
Unit test++
Diffstat (limited to 'libmproxy')
-rw-r--r--libmproxy/console.py2
-rw-r--r--libmproxy/dump.py2
-rw-r--r--libmproxy/proxy.py23
-rw-r--r--libmproxy/utils.py9
4 files changed, 20 insertions, 16 deletions
diff --git a/libmproxy/console.py b/libmproxy/console.py
index ac90bc54..ebc090d3 100644
--- a/libmproxy/console.py
+++ b/libmproxy/console.py
@@ -867,6 +867,7 @@ class Options(object):
setattr(self, i, None)
+#begin nocover
class BodyPile(urwid.Pile):
def __init__(self, master):
h = urwid.Text("Event log")
@@ -909,7 +910,6 @@ class BodyPile(urwid.Pile):
return self.focus_item.keypress( tsize, key )
-#begin nocover
VIEW_CONNLIST = 0
VIEW_FLOW = 1
VIEW_HELP = 2
diff --git a/libmproxy/dump.py b/libmproxy/dump.py
index 86af8be5..4d437b38 100644
--- a/libmproxy/dump.py
+++ b/libmproxy/dump.py
@@ -159,7 +159,7 @@ class DumpMaster(flow.FlowMaster):
def _process_flow(self, f):
if self.filt and not f.match(self.filt):
- return
+ return
if f.response:
sz = utils.pretty_size(len(f.response.content))
diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py
index 3ecd1f32..0c142959 100644
--- a/libmproxy/proxy.py
+++ b/libmproxy/proxy.py
@@ -284,11 +284,16 @@ class Request(HTTPMsg):
modifications to make sure interception works properly.
"""
headers = self.headers.copy()
- utils.try_del(headers, 'proxy-connection')
- utils.try_del(headers, 'keep-alive')
- utils.try_del(headers, 'connection')
- utils.try_del(headers, 'content-length')
- utils.try_del(headers, 'transfer-encoding')
+ utils.del_all(
+ headers,
+ [
+ 'proxy-connection',
+ 'keep-alive',
+ 'connection',
+ 'content-length',
+ 'transfer-encoding'
+ ]
+ )
if not 'host' in headers:
headers["host"] = [self.hostport()]
content = self.content
@@ -426,10 +431,10 @@ class Response(HTTPMsg):
modifications to make sure interception works properly.
"""
headers = self.headers.copy()
- utils.try_del(headers, 'proxy-connection')
- utils.try_del(headers, 'connection')
- utils.try_del(headers, 'keep-alive')
- utils.try_del(headers, 'transfer-encoding')
+ utils.del_all(
+ headers,
+ ['proxy-connection', 'connection', 'keep-alive', 'transfer-encoding']
+ )
content = self.content
if content is not None:
headers["content-length"] = [str(len(content))]
diff --git a/libmproxy/utils.py b/libmproxy/utils.py
index 677d3b22..ff56aa13 100644
--- a/libmproxy/utils.py
+++ b/libmproxy/utils.py
@@ -145,11 +145,10 @@ def hexdump(s):
return parts
-def try_del(dict, key):
- try:
- del dict[key]
- except KeyError:
- pass
+def del_all(dict, keys):
+ for key in keys:
+ if key in dict:
+ del dict[key]
class Headers: