From 85e31feed180420c5ffcc5322c070476fde94fad Mon Sep 17 00:00:00 2001 From: Robin Meis Date: Sun, 27 Apr 2014 12:40:02 +0200 Subject: [PATCH 1/3] Trying a possible workaround Might solve a problem with Python 3.3.x and maybe higher were headers are stored in the output --- document.py | 5 +++++ server.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/document.py b/document.py index 08ec242..417e4e5 100644 --- a/document.py +++ b/document.py @@ -48,6 +48,11 @@ def send (self): #Send the answer to the browser self.connection.send_header(self.header[0], self.header[1]) self.connection.send_response(self.response) self.connection.end_headers() + try: + self.connection.flush_headers() + print ("Headers flushed!") + except: + print ("Headers can't be flushed") if (self.response != 302): self.document = self.document.replace ('', '') #Remove reference mark before sending diff --git a/server.py b/server.py index e03bf45..a722256 100644 --- a/server.py +++ b/server.py @@ -55,6 +55,11 @@ def do_GET(self): self.send_header('Content-type', 'text/html') self.send_response(200) self.end_headers() + try: + self.connection.flush_headers() + print ("Headers flushed!") + except: + print ("Headers can't be flushed") self.wfile.write(bytes(self.document, "utf-8")) elif (path == "/proxy.pac"): self.document = open('proxy.pac', 'r').read() @@ -65,6 +70,11 @@ def do_GET(self): self.send_header('Content-type', 'x-ns-proxy-autoconfig') self.send_response(200) self.end_headers() + try: + self.connection.flush_headers() + print ("Headers flushed!") + except: + print ("Headers can't be flushed") self.wfile.write(bytes(self.document, "utf-8")) elif (arguments["q"] != None): arguments["q"] = arguments["q"].replace(keyword + '+', '', 1) @@ -75,6 +85,11 @@ def do_GET(self): self.send_header('Content-type', 'text/html') self.send_response(404) self.end_headers() + try: + self.connection.flush_headers() + print ("Headers flushed!") + except: + print ("Headers can't be flushed") self.wfile.write(bytes('Not found. Please visit https://github.com/HcDevel/Siri-API/wiki/_pages', "utf-8")) return From 680cb7f2bc84eaf6c141cd48a7fc4bc6c0c88681 Mon Sep 17 00:00:00 2001 From: Robin Meis Date: Sun, 27 Apr 2014 12:50:31 +0200 Subject: [PATCH 2/3] Fixed a small bug --- server.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server.py b/server.py index a722256..9b01ff9 100644 --- a/server.py +++ b/server.py @@ -56,7 +56,7 @@ def do_GET(self): self.send_response(200) self.end_headers() try: - self.connection.flush_headers() + self.flush_headers() print ("Headers flushed!") except: print ("Headers can't be flushed") @@ -71,7 +71,7 @@ def do_GET(self): self.send_response(200) self.end_headers() try: - self.connection.flush_headers() + self.flush_headers() print ("Headers flushed!") except: print ("Headers can't be flushed") @@ -86,7 +86,7 @@ def do_GET(self): self.send_response(404) self.end_headers() try: - self.connection.flush_headers() + self.flush_headers() print ("Headers flushed!") except: print ("Headers can't be flushed") From ebe32039cfac194d3bc2923e8d7fd3ab4a003504 Mon Sep 17 00:00:00 2001 From: HcDevel Date: Sun, 27 Apr 2014 14:30:59 +0200 Subject: [PATCH 3/3] Should fix Issue #2 The response has to be send before the first header. It seems to be a change with Python 3.3.x --- document.py | 7 +------ server.py | 21 +++------------------ 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/document.py b/document.py index 417e4e5..968e37f 100644 --- a/document.py +++ b/document.py @@ -45,14 +45,9 @@ def request (self, url): #Sends a HTTP request (useful for HTTP APIS). If you do return(f.read().decode('utf-8')) def send (self): #Send the answer to the browser - self.connection.send_header(self.header[0], self.header[1]) self.connection.send_response(self.response) + self.connection.send_header(self.header[0], self.header[1]) self.connection.end_headers() - try: - self.connection.flush_headers() - print ("Headers flushed!") - except: - print ("Headers can't be flushed") if (self.response != 302): self.document = self.document.replace ('', '') #Remove reference mark before sending diff --git a/server.py b/server.py index 9b01ff9..fd9b009 100644 --- a/server.py +++ b/server.py @@ -52,14 +52,9 @@ def do_GET(self): #Decide wether a search or the style.css was requested if (path == "/style.css"): self.document = open('style.css', 'r').read() - self.send_header('Content-type', 'text/html') self.send_response(200) + self.send_header('Content-type', 'text/html') self.end_headers() - try: - self.flush_headers() - print ("Headers flushed!") - except: - print ("Headers can't be flushed") self.wfile.write(bytes(self.document, "utf-8")) elif (path == "/proxy.pac"): self.document = open('proxy.pac', 'r').read() @@ -67,14 +62,9 @@ def do_GET(self): self.document = self.document.replace('', google_domain, 1) self.document = self.document.replace('', squid_hostname, 1) self.document = self.document.replace('', str(squid_port), 1) - self.send_header('Content-type', 'x-ns-proxy-autoconfig') self.send_response(200) + self.send_header('Content-type', 'x-ns-proxy-autoconfig') self.end_headers() - try: - self.flush_headers() - print ("Headers flushed!") - except: - print ("Headers can't be flushed") self.wfile.write(bytes(self.document, "utf-8")) elif (arguments["q"] != None): arguments["q"] = arguments["q"].replace(keyword + '+', '', 1) @@ -82,14 +72,9 @@ def do_GET(self): command = commands(self) search(command).search(arguments["q"]) else: - self.send_header('Content-type', 'text/html') self.send_response(404) + self.send_header('Content-type', 'text/html') self.end_headers() - try: - self.flush_headers() - print ("Headers flushed!") - except: - print ("Headers can't be flushed") self.wfile.write(bytes('Not found. Please visit https://github.com/HcDevel/Siri-API/wiki/_pages', "utf-8")) return