def uri_scheme_behind_proxy(request, url):
    """
    Fix uris with forwarded protocol.

    When behind a proxy, django is reached in http, so generated urls are
    using http too.
    """
    if request.META.get("HTTP_X_FORWARDED_PROTO", "http") == "https":
        url = url.replace("http:", "https:", 1)
    return url