Skip to content

Commit

Permalink
Should fix Issue #2
Browse files Browse the repository at this point in the history
The response has to be send before the first header. It seems to be a
change with Python 3.3.x
  • Loading branch information
HcDevel committed Apr 27, 2014
1 parent 680cb7f commit ebe3203
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 24 deletions.
7 changes: 1 addition & 6 deletions document.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ('<replace_with_document_class_dont_remove>', '') #Remove reference mark before sending
Expand Down
21 changes: 3 additions & 18 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,44 +52,29 @@ 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()
self.document = self.document.replace('<keyword>', keyword.lower(), 1)
self.document = self.document.replace('<google_domain>', google_domain, 1)
self.document = self.document.replace('<squid_host>', squid_hostname, 1)
self.document = self.document.replace('<squid_port>', 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)
arguments["q"] = arguments["q"].replace('+', ' ')
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 <a href="https://github.com/HcDevel/Siri-API/wiki/_pages">https://github.com/HcDevel/Siri-API/wiki/_pages</a>', "utf-8"))

return
Expand Down

0 comments on commit ebe3203

Please sign in to comment.