Mercurial > p > roundup > code
diff roundup/cgi/wsgi_handler.py @ 5821:e7b30ab60941
Fix REST API for WSGI
Add dictionary-like headers attribute.
Similar to the apache implementation in same directory but we look up
the given header in the wsgi environment. Environment entries are
mangled (all uppercase, '-' replaced with '_', prefix HTTP_). So on
lookup we mangle the given name first. This allows the rest
implementation (and others) to look up headers.
| author | Ralf Schlatterbeck <rsc@runtux.com> |
|---|---|
| date | Fri, 21 Jun 2019 18:17:42 +0200 |
| parents | 1a835db41674 |
| children | edd9e2c67785 |
line wrap: on
line diff
--- a/roundup/cgi/wsgi_handler.py Sat Jun 15 20:18:35 2019 -0400 +++ b/roundup/cgi/wsgi_handler.py Fri Jun 21 18:17:42 2019 +0200 @@ -20,6 +20,20 @@ BaseHTTPRequestHandler = http_.server.BaseHTTPRequestHandler DEFAULT_ERROR_MESSAGE = http_.server.DEFAULT_ERROR_MESSAGE +class Headers(object): + """ Idea more or less stolen from the 'apache.py' in same directory. + Except that wsgi stores http headers in environment. + """ + def __init__(self, environ): + self.environ = environ + + def mangle_name(self, name): + n = name.replace('-', '_').upper() + return 'HTTP_' + n + + def get(self, name, default = None): + return self.environ.get(self.mangle_name(name), default) + getheader = get class Writer(object): '''Perform a start_response if need be when we start writing.''' @@ -50,6 +64,7 @@ request.wfile = Writer(request) request.__wfile = None + request.headers = Headers(environ) if environ ['REQUEST_METHOD'] == 'OPTIONS': code = 501
