Skip to content
Snippets Groups Projects
utils.py 1022 B
Newer Older
  • Learn to ignore specific revisions
  • from django.conf import settings
    
    
    def full_url(path):
        """
        Given a relative path, return a full url usable for federation purpose
        """
    
        if path.startswith("http://") or path.startswith("https://"):
            return path
    
        root = settings.FUNKWHALE_URL
    
    Eliot Berriot's avatar
    Eliot Berriot committed
        if path.startswith("/") and root.endswith("/"):
    
    Eliot Berriot's avatar
    Eliot Berriot committed
        elif not path.startswith("/") and not root.endswith("/"):
            return root + "/" + path
    
    
    
    def clean_wsgi_headers(raw_headers):
        """
        Convert WSGI headers from CONTENT_TYPE to Content-Type notation
        """
        cleaned = {}
    
    Eliot Berriot's avatar
    Eliot Berriot committed
        non_prefixed = ["content_type", "content_length"]
    
        for raw_header, value in raw_headers.items():
            h = raw_header.lower()
    
    Eliot Berriot's avatar
    Eliot Berriot committed
            if not h.startswith("http_") and h not in non_prefixed:
    
    Eliot Berriot's avatar
    Eliot Berriot committed
            words = h.replace("http_", "", 1).split("_")
            cleaned_header = "-".join([w.capitalize() for w in words])
    
            cleaned[cleaned_header] = value
    
        return cleaned