X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=python%2Fashd-wsgi;h=ae0fc14d0cec31cc313d7b199a036440a9f97ce3;hb=9e70ef793ddcf51edc0f6489eb6f70762380afc0;hp=e43dbc0c04f11f3e6d665cff39ceb2c7ea1c63a0;hpb=3e11d7ede84e52974e41542ed60899ff340088d7;p=ashd.git diff --git a/python/ashd-wsgi b/python/ashd-wsgi index e43dbc0..ae0fc14 100755 --- a/python/ashd-wsgi +++ b/python/ashd-wsgi @@ -1,14 +1,18 @@ #!/usr/bin/python import sys, os, getopt, threading, time -import ashd.proto, ashd.util +import ashd.proto, ashd.util, ashd.perf +try: + import pdm.srv +except: + pdm = None def usage(out): - out.write("usage: ashd-wsgi [-hA] [-p MODPATH] [-l REQLIMIT] HANDLER-MODULE [ARGS...]\n") + out.write("usage: ashd-wsgi [-hA] [-m PDM-SPEC] [-p MODPATH] [-l REQLIMIT] HANDLER-MODULE [ARGS...]\n") reqlimit = 0 modwsgi_compat = False -opts, args = getopt.getopt(sys.argv[1:], "+hAp:l:") +opts, args = getopt.getopt(sys.argv[1:], "+hAp:l:m:") for o, a in opts: if o == "-h": usage(sys.stdout) @@ -19,6 +23,9 @@ for o, a in opts: modwsgi_compat = True elif o == "-l": reqlimit = int(a) + elif o == "-m": + if pdm is not None: + pdm.srv.listen(a) if len(args) < 1: usage(sys.stderr) sys.exit(1) @@ -92,10 +99,6 @@ def dowsgi(req): env["SERVER_PROTOCOL"] = req.ver env["REQUEST_METHOD"] = req.method env["REQUEST_URI"] = req.url - try: - env["PATH_INFO"] = unquoteurl(req.rest) - except: - env["PATH_INFO"] = req.rest name = req.url p = name.find('?') if p >= 0: @@ -104,8 +107,19 @@ def dowsgi(req): else: env["QUERY_STRING"] = "" if name[-len(req.rest):] == req.rest: + # This is the same hack used in call*cgi. name = name[:-len(req.rest)] + try: + pi = unquoteurl(req.rest) + except: + pi = req.rest + if name == '/': + # This seems to be normal CGI behavior, but see callcgi.c for + # details. + pi = "/" + pi + name = "" env["SCRIPT_NAME"] = name + env["PATH_INFO"] = pi if "Host" in req: env["SERVER_NAME"] = req["Host"] if "X-Ash-Server-Port" in req: env["SERVER_PORT"] = req["X-Ash-Server-Port"] if "X-Ash-Protocol" in req and req["X-Ash-Protocol"] == "https": env["HTTPS"] = "on" @@ -160,18 +174,28 @@ def dowsgi(req): resp[:] = status, headers return write - respiter = handler(env, startreq) + reqevent = ashd.perf.request(env) + exc = (None, None, None) try: + respiter = handler(env, startreq) try: - for data in respiter: - write(data) - if resp: - flushreq() - except closed: - pass + try: + for data in respiter: + write(data) + if resp: + flushreq() + except closed: + pass + finally: + if hasattr(respiter, "close"): + respiter.close() + if resp: + reqevent.response(resp) + except: + exc = sys.exc_info() + raise finally: - if hasattr(respiter, "close"): - respiter.close() + reqevent.__exit__(*exc) flightlock = threading.Condition() inflight = 0