This commit is contained in:
Maximilian Hils
2014-08-03 02:34:29 +02:00
parent 10a6d4fbe5
commit 3133136da7
3 changed files with 30 additions and 12 deletions

View File

@@ -34,6 +34,7 @@
from __future__ import absolute_import
import re, sys
from .contrib import pyparsing as pp
from .protocol.http import decoded
class _Token:
@@ -165,10 +166,14 @@ class FBod(_Rex):
code = "b"
help = "Body"
def __call__(self, f):
if f.request.content and re.search(self.expr, f.request.content):
return True
elif f.response and f.response.content and re.search(self.expr, f.response.content):
return True
if f.request and f.request.content:
with decoded(f.request):
if re.search(self.expr, f.request.content):
return True
if f.response and f.response.content:
with decoded(f.response):
if re.search(self.expr, f.response.content):
return True
return False
@@ -176,16 +181,20 @@ class FBodRequest(_Rex):
code = "bq"
help = "Request body"
def __call__(self, f):
if f.request.content and re.search(self.expr, f.request.content):
return True
if f.request and f.request.content:
with decoded(f.request):
if re.search(self.expr, f.request.content):
return True
class FBodResponse(_Rex):
code = "bs"
help = "Response body"
def __call__(self, f):
if f.response and f.response.content and re.search(self.expr, f.response.content):
return True
if f.response and f.response.content:
with decoded(f.response):
if re.search(self.expr, f.response.content):
return True
class FMethod(_Rex):

View File

@@ -6,7 +6,7 @@ import netlib.utils
from netlib.odict import ODict, ODictCaseless
from .primitives import KILL, ProtocolHandler, TemporaryServerChangeMixin, Flow, Error
from ..proxy.connection import ServerConnection
from .. import encoding, utils, filt, controller, stateobject, proxy
from .. import encoding, utils, controller, stateobject, proxy
HDR_FORM_URLENCODED = "application/x-www-form-urlencoded"
CONTENT_MISSING = 0
@@ -791,6 +791,7 @@ class HTTPFlow(Flow):
the expression is invalid, ValueError is raised.
"""
if isinstance(f, basestring):
from .. import filt
f = filt.parse(f)
if not f:
raise ValueError("Invalid filter expression.")

View File

@@ -171,9 +171,7 @@ class TestMatching:
assert self.q("~hs 'header_response: svalue'", s)
assert not self.q("~hs 'header: qvalue'", q)
def test_body(self):
q = self.req()
s = self.resp()
def match_body(self, q, s):
assert not self.q("~b nonexistent", q)
assert self.q("~b content", q)
assert self.q("~b response", s)
@@ -190,6 +188,16 @@ class TestMatching:
assert not self.q("~bs response", q)
assert self.q("~bs response", s)
def test_body(self):
q = self.req()
s = self.resp()
self.match_body(q, s)
q.request.encode("gzip")
s.request.encode("gzip")
s.response.encode("gzip")
self.match_body(q, s)
def test_method(self):
q = self.req()
s = self.resp()