From 08837b2232449c23d35d258efbae464287063ade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 26 Aug 2018 11:17:18 +0200 Subject: [PATCH] Donate CPU: Use CRLF in HTTP responses --- tools/donate-cpu-server.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tools/donate-cpu-server.py b/tools/donate-cpu-server.py index 9b05570ee..ebe7ae91d 100644 --- a/tools/donate-cpu-server.py +++ b/tools/donate-cpu-server.py @@ -72,10 +72,10 @@ def sendAll(connection, data): def httpGetResponse(connection, data, contentType): - resp = 'HTTP/1.1 200 OK\n' - resp += 'Connection: close\n' - resp += 'Content-length: ' + str(len(data)) + '\n' - resp += 'Content-type: ' + contentType + '\n\n' + resp = 'HTTP/1.1 200 OK\r\n' + resp += 'Connection: close\r\n' + resp += 'Content-length: ' + str(len(data)) + '\r\n' + resp += 'Content-type: ' + contentType + '\r\n\r\n' resp += data sendAll(connection, resp) @@ -101,19 +101,15 @@ class HttpClientThread(Thread): filename = os.path.expanduser('~/donated-results/') + package if not os.path.isfile(filename): print('HTTP/1.1 404 Not Found') - connection.send('HTTP/1.1 404 Not Found\n\n') + connection.send('HTTP/1.1 404 Not Found\r\n\r\n') else: f = open(filename,'rt') data = f.read() f.close() httpGetResponse(self.connection, data, 'text/plain') - print('HttpClientThread: sleep 30 seconds..') - time.sleep(30) - print('HttpClientThread: stopping') + finally: time.sleep(1) self.connection.close() - except: - return if __name__ == "__main__": resultPath = os.path.expanduser('~/donated-results')