I have an application running on a server, which can be accessed through a web interface. For that I use the module BaseHTTPServer. On my LAN, this all works perfect without any flaw.
However, when accessing throught the internet, only the first requested page is reaching the server (and honoured). Requests for the inline pictures to which is linked in the first page, never reach the server and users get a "server timeout" message.
I suspect a proxy is keeping the connection to the server open, and thus blocking for a period of time the port for accepting new request.
I tried something like self.connection.close() after writing the content, but this had no result. Also changing the application so that every request would be handled in a new thread, had no result.
I can't figure out if I made an error in the used HTTP protocol. Nor can't I figure out how I can let the server force a connection close.
Does anyone have an idea how to solve this?
Thanx.
class WebRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def address_string(self): #return hostname for logging without doing a DNS lookup.
return str(self.client_address[0])
def do_GET(self):
try:
content=htmlread(self.path)
mime=guess_mime(self.path)
except:
# (...)
mime = mime + '; charset=iso-8859-1'
self.send_response(200)
self.send_header("Connection","close")
self.send_header("Content-type", mime)
self.send_header("Content-Length",str(len(content)))
self.end_headers()
self.wfile.write(content)
def htmlread(file):
# (...)
return content
class Server(threading.Thread):
def run(self):
server = BaseHTTPServer.HTTPServer(('',Global.port), WebRequestHandler)
server.serve_forever()
Server().start()