def get_length(response):
    """
    Get length of response from HTTP response header.

    Falls back to checking the length of the response content if value not
    present in header. Also ensures that we convert from octets to bits for
    use in the bandwidth estimation algorithm

    """
    try:
        length = int(response.headers.get('Content-Length'))
    except TypeError:
        length = len(response.content)
    length = length * 8
    return length