summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--project1/proj1_s4498062/webhttp/server.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/project1/proj1_s4498062/webhttp/server.py b/project1/proj1_s4498062/webhttp/server.py
index f400978..02ed8a6 100644
--- a/project1/proj1_s4498062/webhttp/server.py
+++ b/project1/proj1_s4498062/webhttp/server.py
@@ -27,6 +27,7 @@ class ConnectionHandler(threading.Thread):
self.conn_socket = conn_socket
self.addr = addr
self.timeout = timeout
+ self.done = False
def handle_connection(self):
"""Handle a new connection"""
@@ -39,7 +40,7 @@ class ConnectionHandler(threading.Thread):
# or can we safely assume that in this case the client will close the
# transport channel, so that recv() returns something empty?
try:
- while True:
+ while not self.done:
data = self.conn_socket.recv(4096)
if len(data) == 0:
break
@@ -57,6 +58,9 @@ class ConnectionHandler(threading.Thread):
logging.info("--> (%s) %s" % (self.addr[0], resp.startline()))
self.send(resp)
+ if resp.get_header('Connection') == 'close':
+ self.done = True
+
def send(self, data):
sent = self.conn_socket.send(str(data))
if sent == 0: