Parse an HTTP header from a string, and return an ``HttpHeader``.

    ``header_line`` should only contain one line.
    ``BadHttpHeaderError`` is raised if the string is an invalid header line.

def parse_http_header(header_line):
    """Parse an HTTP header from a string, and return an ``HttpHeader``.

    ``header_line`` should only contain one line.
    ``BadHttpHeaderError`` is raised if the string is an invalid header line.
    """

    header_line = header_line.decode().strip()
    col_idx = header_line.find(':')

    if col_idx < 1:
        raise BadHttpHeaderError('Bad header: {}'.format(repr(header_line)))

    key = header_line[0:col_idx].strip()
    value = header_line[(col_idx+1):].strip()
    return HttpHeader(key=key, value=value)