Assuming the server sends the response body size to the Content-Length response header field, you can do it yourself.
First call Http.request(method="HEAD") to get only the headers, not the body. Then check the Content-Length field of the response to see if it is below your threshold. If so, make a second request with the correct GET or POST method to retrieve the body; otherwise, an error occurs.
If the server does not give you Content-Length (or lies on it), it doesn't seem like there is a way to disable loading after a certain number of bytes.
source share