From 091045c7049f7f851bb8166cac5ecbbf828ca6e2 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Mon, 22 Sep 2008 19:06:03 +0200 Subject: applications.StaticContent: fail on bad request --- wsgitools/applications.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'wsgitools/applications.py') diff --git a/wsgitools/applications.py b/wsgitools/applications.py index 2e6703c..9112e45 100644 --- a/wsgitools/applications.py +++ b/wsgitools/applications.py @@ -1,6 +1,9 @@ class StaticContent: - """This wsgi application provides static content on whatever request it - receives.""" + """ + This wsgi application provides static content on whatever request it + receives with method GET or HEAD (content stripped). If not present, a + content-length header is computed. + """ def __init__(self, status, headers, content): """ @type status: str @@ -31,6 +34,11 @@ class StaticContent: def __call__(self, environ, start_response): """wsgi interface""" assert isinstance(environ, dict) + if environ["REQUEST_METHOD"].upper() not in ["GET", "HEAD"]: + resp = "Request method not implemented" + start_response("501 Not Implemented", + [("Content-length", str(len(resp)))]) + return [resp] start_response(self.status, self.headers) if environ["REQUEST_METHOD"].upper() == "HEAD": return [] -- cgit v1.2.3