import sys, traceback
-from . import env
+from . import env, req, proto
__all__ = ["restart"]
return resp
finally:
req.cleanup()
+
+def handleenv(env, startreq, handler):
+ if not "HTTP_HOST" in env:
+ return proto.simpleerror(env, startreq, 400, "Bad Request", "Request must include Host header.")
+ r = req.origrequest(env)
+ return handle(r, startreq, handler)
ret += c
return ret
+def simpleerror(env, startreq, code, title, msg):
+ buf = """<?xml version="1.0" encoding="US-ASCII"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
+<head>
+<title>%s</title>
+</head>
+<body>
+<h1>%s</h1>
+<p>%s</p>
+</body>
+</html>
+""" % (title, title, htmlq(msg))
+ startreq("%i %s" % (code, title), [("Content-Type", "text/html"), ("Content-Length", str(len(buf)))])
+ return [buf]
+
def urlq(url):
ret = ""
for c in url:
def wsgiwrap(callable):
def wrapper(env, startreq):
- return dispatch.handle(req.origrequest(env), startreq, callable)
+ return dispatch.handleenv(env, startreq, callable)
return wrapper
def stringwrap(charset):