summaryrefslogtreecommitdiff
path: root/paste/request.py
diff options
context:
space:
mode:
authorianb <devnull@localhost>2006-01-22 08:20:50 +0000
committerianb <devnull@localhost>2006-01-22 08:20:50 +0000
commit28b64f8db951766a5c348f090a4689098895c585 (patch)
treec6863b256cb1567975b9d41a1accc0cc1e12ba28 /paste/request.py
parent75c09bdb913a73b4cd0c3fbb4def4a757186a50c (diff)
downloadpaste-28b64f8db951766a5c348f090a4689098895c585.tar.gz
Added a request.parse_headers() function for incoming requests environment mapped to headers. (Should there also be a lazy option that reads the dictionary live from an environment?)
Diffstat (limited to 'paste/request.py')
-rw-r--r--paste/request.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/paste/request.py b/paste/request.py
index 67e765f..cce44b0 100644
--- a/paste/request.py
+++ b/paste/request.py
@@ -208,6 +208,25 @@ def path_info_pop(environ):
environ['SCRIPT_NAME'] += segment
return segment
+_parse_headers_special = {
+ # This is a Zope convention, but we'll allow it here:
+ 'HTTP_CGI_AUTHORIZATION': 'Authorization',
+ 'CONTENT_LENGTH': 'Content-Length',
+ 'CONTENT_TYPE': 'Content-Type',
+ }
+
+def parse_headers(environ):
+ """
+ Parse the headers in the environment (like ``HTTP_HOST``) and
+ yield a sequence of those (header_name, value) tuples.
+ """
+ # @@: Maybe should parse out comma-separated headers?
+ for cgi_var, value in environ.iteritems():
+ if cgi_var in _parse_headers_special:
+ yield _parse_headers_special[cgi_var], value
+ elif cgi_var.startswith('HTTP_'):
+ yield cgi_var[5:].title().replace('_', '-'), value
+
if __name__ == '__main__':
import doctest
doctest.testmod()