Util function to convert django meta to proper headers

This commit is contained in:
Eliot Berriot 2018-03-31 18:39:10 +02:00
parent 043153a520
commit 46d40c7ffa
No known key found for this signature in database
GPG key ID: DD6965E2476E5C27
2 changed files with 55 additions and 0 deletions

View file

@ -12,3 +12,24 @@ def full_url(path):
return root + '/' + path
else:
return root + path
def clean_wsgi_headers(raw_headers):
"""
Convert WSGI headers from CONTENT_TYPE to Content-Type notation
"""
cleaned = {}
non_prefixed = [
'content_type',
'content_length',
]
for raw_header, value in raw_headers.items():
h = raw_header.lower()
if not h.startswith('http_') and h not in non_prefixed:
continue
words = h.replace('http_', '', 1).split('_')
cleaned_header = '-'.join([w.capitalize() for w in words])
cleaned[cleaned_header] = value
return cleaned