Can I do it?
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); curl_slist_free_all(headerlist);
That is, can I free the header list before sending the request? Does curl create a copy?
Not. In source, the setopt function just stores your pointer.
case CURLOPT_HTTPHEADER: /* * Set a list with HTTP headers to use (or replace internals with) */ data->set.headers = va_arg(param, struct curl_slist *); break;