how to clear a specific header in libcurl

333 Views Asked by At
CURL *handle;
struct curl_slist *slist=NULL;
slist = curl_slist_append(slist, "X-libcurl: coolness");
slist = curl_slist_append(slist, "Authorization: Bearer retrffhj");

curl_slist_free_all(slist); /* clears all header list */

How can I clear the header with key Authorization and rest header information should be retained as it is.

2

There are 2 best solutions below

2
Daniel Stenberg On
  1. clear the entire list
  2. make a new list with the header(s) you want in it
  3. use the new list
0
TomJava On
list = curl_slist_append(list, "Accept:");

If you add a header with no content as in 'Accept:' (no data on the right side of the colon), the internally used header will get disabled.

https://curl.se/libcurl/c/CURLOPT_HTTPHEADER.html