curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: Can the CURLOPT_WRITEFUNCTION ever be called when CURLOPT_UPLOAD is set to 1?

From: Daniel Stenberg via curl-library <curl-library_at_cool.haxx.se>
Date: Sat, 16 Jan 2021 23:00:49 +0100 (CET)

On Sat, 16 Jan 2021, Andreas Falkenhahn via curl-library wrote:

> I'm uploading data by passing the remote URL in CURLOPT_URL and providing
> data to upload through my CURLOPT_READFUNCTION. Now I was wondering if there
> are any protocols that actually return data through the
> CURLOPT_WRITEFUNCTION after the upload has completed?

Yes: HTTP for example typically do this.

> For example, when uploading to HTTP I need to listen to the
> CURLOPT_WRITEFUNCTION as well because after the upload has completed, a HTML
> page generated by PHP script that handles the upload is returned. However,
> when doing HTTP uploads I'm not using CURLOPT_READFUNCTION and
> CURLOPT_UPLOAD at all but just CURLOPT_MIMEPOST.

You provide CURLOPT_MIMEPOST *instead of* CURLOPT_READFUNCTION to provide the
data to upload. That's your choice.

> That's why I was wondering if this is some sort of rule, i.e. is it safe to
> assume that CURLOPT_WRITEFUNCTION will never be called when CURLOPT_UPLOAD
> has been set to 1 or are there protocols that use CURLOPT_WRITEFUNCTION even
> when upload has been activated by setting CURLOPT_UPLOAD to 1?

No there isn't. If you CURLOPT_UPLOAD to a HTTP site, you'll most likely get
data back that gets passed to CURLOPT_WRITEFUNCTION.

We should probably make this clear in the docs somewhere, but I'm not really
sure how or where...

--
  / daniel.haxx.se
  | Commercial curl support up to 24x7 is available!
  | Private help, bug fixes, support, ports, new features
  | https://www.wolfssl.com/contact/
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html
Received on 2021-01-16