diff options
| -rw-r--r-- | libmproxy/filt.py | 27 | ||||
| -rw-r--r-- | test/test_filt.py | 6 | 
2 files changed, 32 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 diff --git a/test/test_filt.py b/test/test_filt.py index 1cea34c4..4e059196 100644 --- a/test/test_filt.py +++ b/test/test_filt.py @@ -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() | 
