funquail/api/funkwhale_api/federation/utils.py

34 lines
1,022 B
Python
Raw Normal View History

from django.conf import settings
def full_url(path):
"""
Given a relative path, return a full url usable for federation purpose
"""
2018-07-22 10:20:16 +00:00
if path.startswith("http://") or path.startswith("https://"):
return path
root = settings.FUNKWHALE_URL
2018-06-09 15:36:16 +02:00
if path.startswith("/") and root.endswith("/"):
return root + path[1:]
2018-06-09 15:36:16 +02:00
elif not path.startswith("/") and not root.endswith("/"):
return root + "/" + path
else:
return root + path
def clean_wsgi_headers(raw_headers):
"""
Convert WSGI headers from CONTENT_TYPE to Content-Type notation
"""
cleaned = {}
2018-06-09 15:36:16 +02:00
non_prefixed = ["content_type", "content_length"]
for raw_header, value in raw_headers.items():
h = raw_header.lower()
2018-06-09 15:36:16 +02:00
if not h.startswith("http_") and h not in non_prefixed:
continue
2018-06-09 15:36:16 +02:00
words = h.replace("http_", "", 1).split("_")
cleaned_header = "-".join([w.capitalize() for w in words])
cleaned[cleaned_header] = value
return cleaned