summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2009-10-25 16:05:01 +0100
committerHelmut Grohne <helmut@subdivi.de>2009-10-25 16:05:01 +0100
commit07819487b653165bff4f48d160764d69d24e787b (patch)
tree5655273475ce55f400ab3e77acb3f1eba19de86d
parentda9cefc2b52c00b330ffbb02b41f0fc7bdff8837 (diff)
downloadwsgitools-07819487b653165bff4f48d160764d69d24e787b.tar.gz
extended application.StaticContent
It gained the capability to server content to unknown methods. For a backwards-compatible API this has to be enabled by an optional boolean.
-rw-r--r--wsgitools/applications.py9
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)))])