From 7450e2fcc553f66844b34d5c062a965b8fca28c5 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Wed, 16 Jan 2013 01:16:34 +0100 Subject: [PATCH] Handle missing-Host-header condition. --- wrw/dispatch.py | 8 +++++++- wrw/util.py | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) 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): -- 2.11.0