From: Fredrik Tolf Date: Wed, 16 Jan 2013 00:16:34 +0000 (+0100) Subject: Handle missing-Host-header condition. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=7450e2fcc553f66844b34d5c062a965b8fca28c5;p=wrw.git Handle missing-Host-header condition. --- diff --git a/wrw/dispatch.py b/wrw/dispatch.py index 15ea99e..fa1f669 100644 --- a/wrw/dispatch.py +++ b/wrw/dispatch.py @@ -1,5 +1,5 @@ import sys, traceback -import env +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/util.py b/wrw/util.py index 5ee002b..6368b18 100644 --- a/wrw/util.py +++ b/wrw/util.py @@ -3,7 +3,7 @@ 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 formparams(callable):