def guess_extension_from_headers(h):
    """
    Given headers from an ArXiV e-print response, try and guess what the file
    extension should be.

    Based on: https://arxiv.org/help/mimetypes
    """
    if h.get("content-type") == "application/pdf":
        return ".pdf"
    if (
        h.get("content-encoding") == "x-gzip"
        and h.get("content-type") == "application/postscript"
    ):
        return ".ps.gz"
    if (
        h.get("content-encoding") == "x-gzip"
        and h.get("content-type") == "application/x-eprint-tar"
    ):
        return ".tar.gz"
    if (
        h.get("content-encoding") == "x-gzip"
        and h.get("content-type") == "application/x-eprint"
    ):
        return ".tex.gz"
    if (
        h.get("content-encoding") == "x-gzip"
        and h.get("content-type") == "application/x-dvi"
    ):
        return ".dvi.gz"
    return None