From 66349c97836c5885919f9fd2bce75ddd04bfc39a Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 16 Feb 2011 16:43:35 +1300 Subject: [PATCH] FlowMaster bugfixes and unit tests. --- libmproxy/console.py | 2 +- libmproxy/flow.py | 7 +------ libmproxy/proxy.py | 2 +- test/test_flow.py | 22 ++++++++++++++++++++-- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/libmproxy/console.py b/libmproxy/console.py index 794d5483b..99bf3a4eb 100644 --- a/libmproxy/console.py +++ b/libmproxy/console.py @@ -1334,7 +1334,7 @@ class ConsoleMaster(flow.FlowMaster): self.process_flow(f, r) def handle_response(self, r): - f = flow.FlowMaster.handle_request(self, r) + f = flow.FlowMaster.handle_response(self, r) if f: if f.match(self.stickycookie): hid = (f.request.host, f.request.port) diff --git a/libmproxy/flow.py b/libmproxy/flow.py index e791055f1..9edb9eab6 100644 --- a/libmproxy/flow.py +++ b/libmproxy/flow.py @@ -315,12 +315,7 @@ class FlowMaster(controller.Master): f = self.state.add_response(r) if not f: r.ack() - else: - if f.match(self.stickycookie): - hid = (f.request.host, f.request.port) - if f.response.headers.has_key("set-cookie"): - self.stickyhosts[hid] = f.response.headers["set-cookie"] - self.process_flow(f, r) + return f class FlowWriter: diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index 6093c9365..e2c259660 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -433,7 +433,7 @@ class ServerConnection: if code >= 100 and code <= 199: return self.read_response() if self.request.method == "HEAD" or code == 204 or code == 304: - content = None + content = "" else: content = read_http_body(self.rfile, self, headers, True) return Response(self.request, code, msg, headers, content) diff --git a/test/test_flow.py b/test/test_flow.py index 7db564b2c..7354061b3 100644 --- a/test/test_flow.py +++ b/test/test_flow.py @@ -261,10 +261,28 @@ class uSerialize(libpry.AutoTree): assert l[0] == f - +class uFlowMaster(libpry.AutoTree): + def test_one(self): + s = flow.State() + f = flow.FlowMaster(None, s) + + req = utils.treq() + f.handle_clientconnection(req.client_conn) + assert len(s.flow_list) == 1 + f.handle_request(req) + assert len(s.flow_list) == 1 + f.handle_request(req) + resp = utils.tresp() + resp.request = req + f.handle_response(resp) + assert len(s.flow_list) == 1 + + tests = [ uFlow(), uState(), - uSerialize() + uSerialize(), + uFlowMaster() + ]