On Mon, 2025-02-17 at 11:43 +0100, joan.balagu...@ventusproxy.com
wrote:
> Hi Oleg,
> 
> We are currently using the blocking client. We know that consuming
> the entire entity body is the way to completely read the response and
> free all related resources with the request/response. Now we have a
> requirement coming from a new api that occasionally can return huge
> responses that should be discarded asap by checking its size. It's a
> chunked response, we don't have a content-length header. So, the idea
> should be:
> 
> while (there_are_still_bytes_coming) {
>       numbytes += read_bytes()
>       if (numbytes > MAX_BYTES_TO_READ) {
>               throw exception (max size exceeded")
>       }
> }
> 
> The point is that using this method we are not consuming the entire
> entity body. 
> 
> Is there any way to achieve this, or the only valid way is to read
> the entire body and then check the byte array size?
> 
> Thanks,
> 
> Joan.

Joan,

One can abort the request in order to shut down the underlying
connection but throwing an exception from the response handler is
perfectly valid and is in fact recommended. 

Oleg


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
For additional commands, e-mail: httpclient-users-h...@hc.apache.org

Reply via email to