aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/filt.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-07-14 16:55:21 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-07-14 16:55:21 +1200
commite4079aa746e861c5d39f2812520e33c4d17d1007 (patch)
treea55e399207d470aec4cc61c77fc2c842adc9ed59 /libmproxy/filt.py
parent150814f6a88cc26af1e812d41370dabd78092c33 (diff)
downloadmitmproxy-e4079aa746e861c5d39f2812520e33c4d17d1007.tar.gz
mitmproxy-e4079aa746e861c5d39f2812520e33c4d17d1007.tar.bz2
mitmproxy-e4079aa746e861c5d39f2812520e33c4d17d1007.zip
Add an ~a filter expression, matching an asset content type in responses.
Asset content types are Javascript, images, Flash and CSS. This is useful because doing a quick "!~a" while auditing an app will filter out the majority of the static asset cruft, letting you focus on what matters.
Diffstat (limited to 'libmproxy/filt.py')
-rw-r--r--libmproxy/filt.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/libmproxy/filt.py b/libmproxy/filt.py
index 4314f2d5..233cbb62 100644
--- a/libmproxy/filt.py
+++ b/libmproxy/filt.py
@@ -24,6 +24,12 @@
Patterns are matched against "name: value" strings. Field names are
all-lowercase.
+ ~a Asset content-type in response. Asset content types are:
+ text/javascript
+ application/x-javascript
+ text/css
+ image/*
+ application/x-shockwave-flash
~h rex Header line in either request or response
~hq rex Header in request
~hs rex Header in response
@@ -95,6 +101,24 @@ def _check_content_type(expr, o):
return False
+class FAsset(_Action):
+ code = "a"
+ help = "Match asset in response: CSS, Javascript, Flash, images."
+ ASSET_TYPES = [
+ "text/javascript",
+ "application/x-javascript",
+ "text/css",
+ "image/.*",
+ "application/x-shockwave-flash"
+ ]
+ def __call__(self, f):
+ if f.response:
+ for i in self.ASSET_TYPES:
+ if _check_content_type(i, f.response):
+ return True
+ return False
+
+
class FContentType(_Rex):
code = "t"
help = "Content-type header"
@@ -258,6 +282,7 @@ class FNot(_Token):
filt_unary = [
FReq,
FResp,
+ FAsset,
FErr
]
filt_rex = [
@@ -322,7 +347,7 @@ bnf = _make()
def parse(s):
try:
return bnf.parseString(s, parseAll=True)[0]
- except pp.ParseException:
+ except pp.ParseException, v:
return None
except ValueError:
return None