mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-01-30 14:58:38 +00:00
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.
This commit is contained in:
parent
150814f6a8
commit
e4079aa746
@ -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
|
||||
|
@ -112,6 +112,12 @@ class TestMatching:
|
||||
def q(self, q, o):
|
||||
return filt.parse(q)(o)
|
||||
|
||||
def test_asset(self):
|
||||
s = self.resp()
|
||||
assert not self.q("~a", s)
|
||||
s.response.headers["content-type"] = ["text/javascript"]
|
||||
assert self.q("~a", s)
|
||||
|
||||
def test_fcontenttype(self):
|
||||
q = self.req()
|
||||
s = self.resp()
|
||||
|
Loading…
Reference in New Issue
Block a user