derived from CGIHTTPServer.py
Michael Ströder
michael.stroeder at inka.de
Thu Feb 17 20:21:22 EST 2000
HI!
I have sub-classed my own CGI-handler from
CGIHTTPServer.CGIHTTPRequestHandler and have overriden the method
run_cgi to write a persistent stand-alone web gateway. I copied some
code from CGIHTTPServer.py and modified it for my needs for method
run_cgi. The script (the function HandleHTTPRequest()) runs just
fine and outputs everything to the browser without error. But the
browser does not stop loading, the connection is not closed.
Can somebody figure out what I have to do? Code of sub-class below.
Thanks a lot.
Ciao, Michael.
-------------------- snip ---------------------
# Sub-class CGIHTTPServer
class MyHTTPHandler(CGIHTTPServer.CGIHTTPRequestHandler):
def do_POST(self):
self.run_cgi()
def send_head(self):
return self.run_cgi()
def run_cgi(self):
dir, rest = '', self.path[1:]
i = string.rfind(rest, '?')
if i >= 0:
rest, query = rest[:i], rest[i+1:]
else:
query = ''
i = string.find(rest, '/')
if i >= 0:
script, rest = rest[:i], rest[i:]
else:
script, rest = rest, ''
scriptname = dir + '/' + script
scriptfile = self.translate_path(scriptname)
if not os.path.isfile(scriptfile):
self.send_error(403, "CGI script is not a plain file
(%s)" %
`scriptname`)
return
self.send_response(200, "Script output follows")
self.wfile.flush() # Always flush before forking
os.dup2(self.rfile.fileno(), 0)
os.dup2(self.wfile.fileno(), 1)
content_length_str =
self.headers.getheader('content-length')
if content_length_str:
content_length = int(content_length_str)
else:
content_length = -1
uqrest = urllib.unquote(rest)
HandleHTTPRequest(
self.command,
self.server.server_name,
self.server.server_port,
scriptname,
uqrest,
query,
content_length,
self.headers.getheader('user-agent'),
string.split(self.headers.getheader('accept-charset'),',')[0],
self.client_address[0]
)
sys.stdout.flush()
self.wfile.flush()
return
-------------------- snip ---------------------
More information about the Python-list
mailing list