def read_body(response, max_bytes=None):
    """Return a `Deferred` yielding at most *max_bytes* bytes from the
    body of a Twisted Web *response*, or the whole body if *max_bytes*
    is `None`."""
    finished = Deferred()
    response.deliverBody(TruncatingReadBodyProtocol(
        response.code, response.phrase, finished, max_bytes))
    return finished