From 3133136da763107172b1464b777362b7b7f8e54e Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sun, 3 Aug 2014 02:34:29 +0200 Subject: fix #307 --- libmproxy/filt.py | 25 +++++++++++++++++-------- libmproxy/protocol/http.py | 3 ++- 2 files changed, 19 insertions(+), 9 deletions(-) (limited to 'libmproxy') diff --git a/libmproxy/filt.py b/libmproxy/filt.py index bd429fa3..e17ed735 100644 --- a/libmproxy/filt.py +++ b/libmproxy/filt.py @@ -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): diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py index 6837327b..aed538ef 100644 --- a/libmproxy/protocol/http.py +++ b/libmproxy/protocol/http.py @@ -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.") -- cgit v1.2.3