cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Question regarding limiting the response size in a client using libcurl

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Sat, 3 May 2014 00:43:26 +0200 (CEST)

On Tue, 29 Apr 2014, Sachin Nikumbh wrote:

> I want to stop reading response and close connection from the client if the
> total data received exceeds some preset response size limit.
>
> So, I want the responseBodyReceiver to look something like:

> if( newSize > RESPONSE_SIZE_LIMIT ){
>
> // I would like to stop reading and exit. But want to
> // break connection from the client side before I exit

The documentation for CURLOPT_WRITEFUNCTION explains:

   Return the number of bytes actually taken care of. If that amount differs
   from the amount passed to your function, it'll signal an error to the
   library. This will abort the transfer and return CURLE_WRITE_ERROR.

... that will lead to the connection getting closed because it cannot be
re-used when forcibly getting stopped like that.

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2014-05-03