mirror of
https://github.com/zhigang1992/mitmproxy.git
synced 2026-04-29 04:35:02 +08:00
fix #307
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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.")
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user