I'm writing a network library based on cpr and libcurl library.
In post function, I wrote something like this:
cpr::Response r;
{
std::lock_guard<std::mutex> lock(m_lockPostClient);
if (m_doh == "on") {
curl_easy_setopt(m_postClient.GetCurlHolder()->handle, CURLOPT_DOH_URL, m_doh_url.c_str());
}
m_postClient.SetTimeout(cpr::Timeout((int)timeout));
m_postClient.SetConnectTimeout(cpr::ConnectTimeout((int)timeout));
m_postClient.SetUrl(cpr::Url{ url });
m_postClient.SetHeader(header);
m_postClient.SetBody(cpr::Body(body));
m_postClient.SetVerifySsl(cpr::VerifySsl(true));
r = m_postClient.Post();
}
Which m_postClient is the cpr::Session variable. m_doh and m_doh_url sets the DoH when posting.
However, after curl_easy_setopt function, it seems like DoH does not take effect immediately in the Post() following. BTW, it does not looks like two different threads.
I need to wait sometime to make the DoH setting taken effect. It will taken effect after several post request. It really confused me, could anyone tell me reason?