aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libmproxy/proxy.py3
-rw-r--r--test/test_server.py16
-rw-r--r--test/tservers.py18
3 files changed, 30 insertions, 7 deletions
diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py
index 6d476c7b..c8fac5f4 100644
--- a/libmproxy/proxy.py
+++ b/libmproxy/proxy.py
@@ -194,7 +194,8 @@ class ProxyHandler(tcp.BaseHandler):
sc.rfile.first_byte_timestamp, utils.timestamp()
)
response_reply = self.channel.ask(response)
- # Not replying to the server invalidates the server connection, so we terminate.
+ # Not replying to the server invalidates the server
+ # connection, so we terminate.
if response_reply == KILL:
sc.terminate()
diff --git a/test/test_server.py b/test/test_server.py
index 58dfee58..5cba891c 100644
--- a/test/test_server.py
+++ b/test/test_server.py
@@ -2,6 +2,7 @@ import socket, time
from netlib import tcp
from libpathod import pathoc
import tutils, tservers
+from libmproxy import flow
"""
Note that the choice of response code in these tests matters more than you
@@ -144,3 +145,18 @@ class TestProxy(tservers.HTTPProxTest):
request = self.master.state.view[1].request
assert request.timestamp_end - request.timestamp_start <= 0.1
+
+
+class MasterFakeResponse(tservers.TestMaster):
+ def handle_request(self, m):
+ resp = tutils.tresp()
+ m.reply(resp)
+
+
+class TestFakeResponse(tservers.HTTPProxTest):
+ masterclass = MasterFakeResponse
+ def test_kill(self):
+ p = self.pathoc()
+ f = self.pathod("200")
+ assert "header_response" in f.headers.keys()
+
diff --git a/test/tservers.py b/test/tservers.py
index 4cbdc942..3fdb8d13 100644
--- a/test/tservers.py
+++ b/test/tservers.py
@@ -29,16 +29,20 @@ class TestMaster(flow.FlowMaster):
flow.FlowMaster.__init__(self, s, state)
self.testq = testq
- def handle(self, m):
- flow.FlowMaster.handle(self, m)
+ def handle_request(self, m):
+ flow.FlowMaster.handle_request(self, m)
+ m.reply()
+
+ def handle_response(self, m):
+ flow.FlowMaster.handle_response(self, m)
m.reply()
class ProxyThread(threading.Thread):
- def __init__(self, testq, config):
- self.tmaster = TestMaster(testq, config)
- controller.should_exit = False
+ def __init__(self, tmaster):
threading.Thread.__init__(self)
+ self.tmaster = tmaster
+ controller.should_exit = False
@property
def port(self):
@@ -52,6 +56,7 @@ class ProxyThread(threading.Thread):
class ProxTestBase:
+ masterclass = TestMaster
@classmethod
def setupAll(cls):
cls.tqueue = Queue.Queue()
@@ -61,7 +66,8 @@ class ProxTestBase:
certfile=tutils.test_data.path("data/testkey.pem"),
**pconf
)
- cls.proxy = ProxyThread(cls.tqueue, config)
+ tmaster = cls.masterclass(cls.tqueue, config)
+ cls.proxy = ProxyThread(tmaster)
cls.proxy.start()
@property