Exemplo n.º 1
0
def get_filename(connection: HTTPResponse):
    content_disposition = connection.getheader('Content-Disposition')
    if content_disposition is not None:
        # !!!! I have yet to find a server that returns this for a file download. I have not been able to test this on
        # a proper response. I have made mock responses to test this.
        # Based off of https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition
        dispositions = content_disposition.strip().split("; ")
        for disposition in dispositions:
            if "=" in disposition:
                key, value = disposition.split("=")
                if key == 'filename':
                    return value
    # Will return '' if the path is '/path/to/something
    return Path(urlparse(connection.geturl()).path).name
Exemplo n.º 2
0
def get_ip(connection: HTTPResponse) -> str:
    """
    Finds IP of connection.
    """
    ip = socket.gethostbyname(urlparse(connection.geturl()).hostname)
    return ip