curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: Write callback function when following HTTP redirections

From: Daniel Stenberg via curl-library <curl-library_at_cool.haxx.se>
Date: Mon, 15 Apr 2019 22:31:38 +0200 (CEST)

On Mon, 15 Apr 2019, Nicolas Roeser via curl-library wrote:

> My problem is that I do not know where the boundary between header and body
> is if the download has been aborted. To make things worse, I have the
> feeling that it may be difficult to properly detect.

I read your email several times and I can't figure out *why* you need to
detect that boundary yourself. Why can't you use the different callbacks for
header and body as then you can simply lean on libcurl's detection that it
always does?

> I would like to clear the receive buffer each time the client starts reading
> a new resource.

And that is not before you invoke curl? When you ask libcurl to follow a
redirect, the only body that is sent to the write callback is that if the URL
that isn't itself a redirect.

> I first thought that I might disable CURLOPT_HEADER and handle some headers
> differently from what is done now. But this seems not to help with my
> problem of identifying when to clear my receive buffer as long as
> CURLOPT_FOLLOWLOCATION is on.

Do you mean a receive buffer for the *headers* of the final non-redirect URL?
If so, then I presume you can just detect a 2xx response code and take that as
start of the last set of headers.

> I have a feeling that the write callback function will never be called with
> data from two HTTP responses at once (that is, will never cross
> redirections).

I'm not following this. How can there be two HTTP responses at once?

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html
Received on 2019-04-15