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: CURLOPT_HEADERFUNCTION and buffer modifications

From: Daniel Stenberg via curl-library <curl-library_at_cool.haxx.se>
Date: Thu, 3 Oct 2019 11:56:23 +0200 (CEST)

On Thu, 3 Oct 2019, Clément Gregoire via curl-library wrote:

> I'm using CURLOPT_HEADERFUNCTION to read/parse headers, and it'd be useful
> for me if I could replace some characters with for example the '\0'. Typical
> usage would be for strtok. Is this allowed ? I know the header callback
> buffer member is `char*` and not `const char*` but I still wanted to make
> sure.

A fair question as it isn't specifically mentioned in the documentation. We
should probably add something to this effect.

I would strongly discourage doing that. The prototype and callbacks should be
considered a 'const char *'. Not using that was just an omission (by me) and
stuck like this to not rock the boat.

You will *likely* be able to write to that buffer without it hurting, but
that's not something we can guarantee will continue to work nor that it worked
correctly in older libcurl versions.

That's also why strtok_r() and friends were invented! ;-)

-- 
  / daniel.haxx.se | Get the best commercial curl support there is - from me
                   | 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.haxx.se/mail/etiquette.html
Received on 2019-10-03