FlowMaster bugfixes and unit tests.

This commit is contained in:
Aldo Cortesi 2011-02-16 16:43:35 +13:00
parent 27f0765cdd
commit 66349c9783
4 changed files with 23 additions and 10 deletions

View File

@ -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)

View File

@ -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:

View File

@ -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)

View File

@ -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()
]