aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/filt.py
diff options
context:
space:
mode:
Diffstat (limited to 'libmproxy/filt.py')
-rw-r--r--libmproxy/filt.py42
1 files changed, 26 insertions, 16 deletions
diff --git a/libmproxy/filt.py b/libmproxy/filt.py
index 6abc4a11..7cd0f4df 100644
--- a/libmproxy/filt.py
+++ b/libmproxy/filt.py
@@ -77,17 +77,19 @@ class FResp(_Action):
class _Rex(_Action):
+ flags = 0
+
def __init__(self, expr):
self.expr = expr
try:
- self.re = re.compile(self.expr)
+ self.re = re.compile(self.expr, self.flags)
except:
raise ValueError("Cannot compile expression.")
def _check_content_type(expr, o):
- val = o.headers["content-type"]
- if val and re.search(expr, val[0]):
+ val = o.headers.get("content-type")
+ if val and re.search(expr, val):
return True
return False
@@ -145,11 +147,12 @@ class FResponseContentType(_Rex):
class FHead(_Rex):
code = "h"
help = "Header"
+ flags = re.MULTILINE
def __call__(self, f):
- if f.request.headers.match_re(self.expr):
+ if f.request and self.re.search(str(f.request.headers)):
return True
- elif f.response and f.response.headers.match_re(self.expr):
+ if f.response and self.re.search(str(f.response.headers)):
return True
return False
@@ -157,18 +160,20 @@ class FHead(_Rex):
class FHeadRequest(_Rex):
code = "hq"
help = "Request header"
+ flags = re.MULTILINE
def __call__(self, f):
- if f.request.headers.match_re(self.expr):
+ if f.request and self.re.search(str(f.request.headers)):
return True
class FHeadResponse(_Rex):
code = "hs"
help = "Response header"
+ flags = re.MULTILINE
def __call__(self, f):
- if f.response and f.response.headers.match_re(self.expr):
+ if f.response and self.re.search(str(f.response.headers)):
return True
@@ -178,10 +183,10 @@ class FBod(_Rex):
def __call__(self, f):
if f.request and f.request.content:
- if re.search(self.expr, f.request.get_decoded_content()):
+ if self.re.search(f.request.get_decoded_content()):
return True
if f.response and f.response.content:
- if re.search(self.expr, f.response.get_decoded_content()):
+ if self.re.search(f.response.get_decoded_content()):
return True
return False
@@ -192,7 +197,7 @@ class FBodRequest(_Rex):
def __call__(self, f):
if f.request and f.request.content:
- if re.search(self.expr, f.request.get_decoded_content()):
+ if self.re.search(f.request.get_decoded_content()):
return True
@@ -202,24 +207,26 @@ class FBodResponse(_Rex):
def __call__(self, f):
if f.response and f.response.content:
- if re.search(self.expr, f.response.get_decoded_content()):
+ if self.re.search(f.response.get_decoded_content()):
return True
class FMethod(_Rex):
code = "m"
help = "Method"
+ flags = re.IGNORECASE
def __call__(self, f):
- return bool(re.search(self.expr, f.request.method, re.IGNORECASE))
+ return bool(self.re.search(f.request.method))
class FDomain(_Rex):
code = "d"
help = "Domain"
+ flags = re.IGNORECASE
def __call__(self, f):
- return bool(re.search(self.expr, f.request.host, re.IGNORECASE))
+ return bool(self.re.search(f.request.host))
class FUrl(_Rex):
@@ -234,21 +241,24 @@ class FUrl(_Rex):
return klass(*toks)
def __call__(self, f):
- return re.search(self.expr, f.request.url)
+ return self.re.search(f.request.url)
+
class FSrc(_Rex):
code = "src"
help = "Match source address"
def __call__(self, f):
- return f.client_conn.address and re.search(self.expr, repr(f.client_conn.address))
+ return f.client_conn.address and self.re.search(repr(f.client_conn.address))
+
class FDst(_Rex):
code = "dst"
help = "Match destination address"
def __call__(self, f):
- return f.server_conn.address and re.search(self.expr, repr(f.server_conn.address))
+ return f.server_conn.address and self.re.search(repr(f.server_conn.address))
+
class _Int(_Action):
def __init__(self, num):