paulb@110 | 1 | #!/usr/bin/env python |
paulb@110 | 2 | |
paulb@110 | 3 | """ |
paulb@110 | 4 | Environment helper functions. |
paulb@110 | 5 | """ |
paulb@110 | 6 | |
paulb@110 | 7 | def get_headers(env): |
paulb@110 | 8 | |
paulb@110 | 9 | """ |
paulb@110 | 10 | Get the headers from the given environment 'env', which should be a |
paulb@110 | 11 | dictionary-like object. |
paulb@110 | 12 | |
paulb@110 | 13 | Returns a dictionary-like object containing likely headers. |
paulb@110 | 14 | """ |
paulb@110 | 15 | |
paulb@110 | 16 | headers = {} |
paulb@110 | 17 | for cgi_key, value in env.items(): |
paulb@110 | 18 | if cgi_key.startswith("HTTP_"): |
paulb@110 | 19 | header_name = cgi_key[len("HTTP_"):].replace("_", "-").lower() |
paulb@110 | 20 | headers[header_name] = value |
paulb@110 | 21 | |
paulb@110 | 22 | return headers |
paulb@110 | 23 | |
paulb@110 | 24 | # vim: tabstop=4 expandtab shiftwidth=4 |