aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/filt.py
diff options
context:
space:
mode:
Diffstat (limited to 'libmproxy/filt.py')
-rw-r--r--libmproxy/filt.py55
1 files changed, 30 insertions, 25 deletions
diff --git a/libmproxy/filt.py b/libmproxy/filt.py
index cfd3a1bc..7cd0f4df 100644
--- a/libmproxy/filt.py
+++ b/libmproxy/filt.py
@@ -35,7 +35,6 @@ from __future__ import absolute_import
import re
import sys
import pyparsing as pp
-from .models import decoded
class _Token:
@@ -78,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
@@ -146,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
@@ -158,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
@@ -179,13 +183,11 @@ class FBod(_Rex):
def __call__(self, f):
if f.request and f.request.content:
- with decoded(f.request):
- if re.search(self.expr, f.request.content):
- return True
+ if self.re.search(f.request.get_decoded_content()):
+ return True
if f.response and f.response.content:
- with decoded(f.response):
- if re.search(self.expr, f.response.content):
- return True
+ if self.re.search(f.response.get_decoded_content()):
+ return True
return False
@@ -195,9 +197,8 @@ class FBodRequest(_Rex):
def __call__(self, f):
if f.request and f.request.content:
- with decoded(f.request):
- if re.search(self.expr, f.request.content):
- return True
+ if self.re.search(f.request.get_decoded_content()):
+ return True
class FBodResponse(_Rex):
@@ -206,25 +207,26 @@ class FBodResponse(_Rex):
def __call__(self, f):
if f.response and f.response.content:
- with decoded(f.response):
- if re.search(self.expr, f.response.content):
- return True
+ 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):
@@ -239,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):