def get_upgrade_response(connection):
    """
    This function reads from the socket until the HTTP/1.1 end-of-headers
    sequence (CRLFCRLF) is received. It then checks what the status code of the
    response is.

    This is not a substitute for proper HTTP/1.1 parsing, but it's good enough
    for example purposes.
    """
    data = b''
    while b'\r\n\r\n' not in data:
        data += connection.recv(8192)
    headers, rest = data.split(b'\r\n\r\n', 1)
    split_headers = headers.split()
    if split_headers[1] != b'101':
        raise RuntimeError('Not upgrading!')
    return rest
