From: Fredrik Tolf Date: Wed, 16 Jan 2013 00:17:51 +0000 (+0100) Subject: Merge branch 'master' into python3 X-Git-Url: http://dolda2000.com/gitweb/?p=wrw.git;a=commitdiff_plain;h=10ba659d32518d2d09b12ada86a380798b378fe7;hp=5d0ae1011cdaf805d3d4b7cefb204f70dfd03689 Merge branch 'master' into python3 Conflicts: wrw/dispatch.py --- diff --git a/wrw/dispatch.py b/wrw/dispatch.py index e51559e..10cc2f6 100644 --- a/wrw/dispatch.py +++ b/wrw/dispatch.py @@ -1,5 +1,5 @@ import sys, traceback -from . import env +from . import env, req, proto __all__ = ["restart"] @@ -73,3 +73,9 @@ def handle(req, startreq, handler): 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) diff --git a/wrw/proto.py b/wrw/proto.py index 8474b3a..4cf1951 100644 --- a/wrw/proto.py +++ b/wrw/proto.py @@ -85,6 +85,22 @@ def htmlq(html): ret += c return ret +def simpleerror(env, startreq, code, title, msg): + buf = """ + + + +%s + + +

%s

+

%s

+ + +""" % (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: diff --git a/wrw/util.py b/wrw/util.py index a7f1e4c..5347ce4 100644 --- a/wrw/util.py +++ b/wrw/util.py @@ -3,7 +3,7 @@ from . import req, dispatch, session, form 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):