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