SSL Context Callback
Implements #1019.
As an extension to #1020 this PR adds a function that gets called by libcurl just before the initialization of an SSL connection after having processed all other SSL related options to give a last chance to an application to modify the behavior of the SSL initialization.
Ref: https://curl.se/libcurl/c/CURLOPT_SSL_CTX_FUNCTION.html
How to use:
size_t count{0};
cpr::ssl::SslCtxCallback sslCtxCb{[](const std::shared_ptr<cpr::CurlHolder>& /*curl_holder*/, void* /*ssl_ctx*/, intptr_t userdata) {
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast)
size_t* count = reinterpret_cast<size_t*>(userdata);
(*count)++;
return CURLE_OK;
},
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast)
reinterpret_cast<intptr_t>(&count)};
cpr::SslOptions sslOpts = cpr::Ssl(sslCtxCb);
cpr::Get(url, sslOpts);
EXPECT_EQ(count, 1);
This option is incompatible with cpr::ssl::CaBuffer. In case both options are present an instance of std::logic_error gets thrown while performing the request.
Docs: https://github.com/libcpr/docs/pull/44
Currently still WIP since something seams to be broken when using this functionality when cpr is used via fetch content e.g. in our example repo.
Unit tests as well as sanitizers do not find anything yet...