diff options
Diffstat (limited to 'libmproxy/flow.py')
-rw-r--r-- | libmproxy/flow.py | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/libmproxy/flow.py b/libmproxy/flow.py index 61b2a241..d79f2862 100644 --- a/libmproxy/flow.py +++ b/libmproxy/flow.py @@ -1,18 +1,3 @@ -# Copyright (C) 2012 Aldo Cortesi -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - """ This module provides more sophisticated flow tracking. These match requests with their responses, and provide filtering and interception facilities. @@ -221,15 +206,21 @@ class HTTPMsg(StateObject): Decodes content based on the current Content-Encoding header, then removes the header. If there is no Content-Encoding header, no action is taken. + + Returns True if decoding succeeded, False otherwise. """ ce = self.headers.get_first("content-encoding") if not self.content or ce not in encoding.ENCODINGS: - return - self.content = encoding.decode( + return False + data = encoding.decode( ce, self.content ) + if data is None: + return False + self.content = data del self.headers["content-encoding"] + return True def encode(self, e): """ @@ -627,7 +618,7 @@ class Response(HTTPMsg): self.headers, self.content = headers, content self.cert = cert self.timestamp_start = timestamp_start or utils.timestamp() - self.timestamp_end = max(timestamp_end or utils.timestamp(), timestamp_start) + self.timestamp_end = timestamp_end or utils.timestamp() self.replay = False def _refresh_cookie(self, c, delta): @@ -790,6 +781,7 @@ class Response(HTTPMsg): cookies.append((cookie_name, (cookie_value, cookie_parameters))) return dict(cookies) + class ClientDisconnect: """ A client disconnection event. @@ -1375,6 +1367,18 @@ class FlowMaster(controller.Master): self.stream = None app.mapp.config["PMASTER"] = self + def start_app(self, domain, ip): + self.server.apps.add( + app.mapp, + domain, + 80 + ) + self.server.apps.add( + app.mapp, + ip, + 80 + ) + def add_event(self, e, level="info"): """ level: info, error @@ -1575,6 +1579,13 @@ class FlowMaster(controller.Master): self.run_script_hook("clientdisconnect", r) r.reply() + def handle_serverconnection(self, sc): + # To unify the mitmproxy script API, we call the script hook "serverconnect" rather than "serverconnection". + # As things are handled differently in libmproxy (ClientConnect + ClientDisconnect vs ServerConnection class), + # there is no "serverdisonnect" event at the moment. + self.run_script_hook("serverconnect", sc) + sc.reply() + def handle_error(self, r): f = self.state.add_error(r) if f: @@ -1653,7 +1664,7 @@ class FlowReader: try: while 1: data = tnetstring.load(self.fo) - if tuple(data["version"]) != version.IVERSION: + if tuple(data["version"][:2]) != version.IVERSION[:2]: v = ".".join(str(i) for i in data["version"]) raise FlowReadError("Incompatible serialized data version: %s"%v) off = self.fo.tell() @@ -1676,4 +1687,3 @@ class FilteredFlowWriter: d = f._get_state() tnetstring.dump(d, self.fo) - |