Add a domain match filter (~d regex)

This commit is contained in:
Aldo Cortesi 2012-07-06 22:21:44 +12:00
parent c4426952ad
commit d02bcade3a
3 changed files with 16 additions and 2 deletions

View File

@ -182,6 +182,13 @@ class FMethod(_Rex):
return bool(re.search(self.expr, f.request.method, re.IGNORECASE)) return bool(re.search(self.expr, f.request.method, re.IGNORECASE))
class FDomain(_Rex):
code = "d"
help = "Domain"
def __call__(self, f):
return bool(re.search(self.expr, f.request.host, re.IGNORECASE))
class FUrl(_Rex): class FUrl(_Rex):
code = "u" code = "u"
help = "URL" help = "URL"
@ -260,6 +267,7 @@ filt_rex = [
FBodResponse, FBodResponse,
FBod, FBod,
FMethod, FMethod,
FDomain,
FUrl, FUrl,
FRequestContentType, FRequestContentType,
FResponseContentType, FResponseContentType,

View File

@ -195,6 +195,12 @@ class TestMatching:
q.request.method = "oink" q.request.method = "oink"
assert not self.q("~m get", q) assert not self.q("~m get", q)
def test_domain(self):
q = self.req()
s = self.resp()
assert self.q("~d host", q)
assert not self.q("~d none", q)
def test_url(self): def test_url(self):
q = self.req() q = self.req()
s = self.resp() s = self.resp()