diff options
Diffstat (limited to 'wsgitools/applications.py')
-rw-r--r-- | wsgitools/applications.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/wsgitools/applications.py b/wsgitools/applications.py index 286ab9b..63ed63c 100644 --- a/wsgitools/applications.py +++ b/wsgitools/applications.py @@ -14,7 +14,7 @@ class StaticContent: receives with method GET or HEAD (content stripped). If not present, a content-length header is computed. """ - def __init__(self, status, headers, content): + def __init__(self, status, headers, content, anymethod=False): """ @type status: str @param status: is the HTTP status returned to the browser (ex: "200 OK") @@ -24,12 +24,16 @@ class StaticContent: @type content: basestring @param content: contains the data to be delivered to the client. It is either a string or some kind of iterable yielding strings. + @type anymethod: boolean + @param anymethod: determines whether any request method should be + answered with this response instead of a 501 """ assert isinstance(status, str) assert isinstance(headers, list) assert isinstance(content, basestring) or hasattr(content, "__iter__") self.status = status self.headers = headers + self.anymethod = anymethod length = -1 if isinstance(content, basestring): self.content = [content] @@ -44,7 +48,8 @@ class StaticContent: def __call__(self, environ, start_response): """wsgi interface""" assert isinstance(environ, dict) - if environ["REQUEST_METHOD"].upper() not in ["GET", "HEAD"]: + if environ["REQUEST_METHOD"].upper() not in ["GET", "HEAD"] and \ + not self.anymethod: resp = "Request method not implemented" start_response("501 Not Implemented", [("Content-length", str(len(resp)))]) |