import re


def headers_to_strings(headers, titled_key=False):
    """Convert HTTP headers to multi-line string."""
    return "\n".join(
        [
            "{0}: {1}".format(
                key.title() if titled_key else key,
                re.sub(
                    r"Credential=([^/]+)",
                    "Credential=*REDACTED*",
                    re.sub(
                        r"Signature=([0-9a-f]+)",
                        "Signature=*REDACTED*",
                        value,
                    ),
                ) if titled_key else value,
            ) for key, value in headers.items()
        ]
    )