import re


def determine_file_extension_from_response(response):
    """
    This retrieves the file extension from the response.
    :param requests.Response response: the response object from the download
    :return the extension indicating the file compression(e.g. zip, tgz)
    :rtype str
    """
    content_disposition = response.headers.get('content-disposition')
    ext = None
    if content_disposition:
        file_name = re.findall("filename\\*?=([^;]+)", content_disposition)
        file_name = file_name[0].strip().strip('"')
        ext = file_name.split(".")[1]

    if ext is None:
        message = f"Could not determine compression type of: {content_disposition}"
        raise Exception(message)
    return ext