mrtazz / restclient-cpp

C++ client for making HTTP/REST requests
http://code.mrtazz.com/restclient-cpp/
MIT License
1.57k stars 377 forks source link

seeds SetSSLContextCallback #178

Open aryanbdps9 opened 2 years ago

aryanbdps9 commented 2 years ago

There should be a way to set SSL context callback function (CURLOPT_SSL_CTX_FUNCTION). Personally, I needed to call SSL_CTX_set_default_verify_paths inside this callback, but it could be useful to others as well.

Sample code:

static CURLcode sslctx_fn(CURL *curl, void *sslctx, void *parm)
{
  // Do whatever you want, for example:
  // SSL_CTX_set_default_verify_paths(static_cast<SSL_CTX*>(sslctx));

  // Return CURLE_OK if everything looks fine.
  return CURLE_OK;
}

void foo()
{
  ...

  conn->SetVerifyPeer(true);
  conn->SetSSLContextCallback(*sslctx_fn);
  RestClient::Response res = conn->get("/get");
  EXPECT_EQ(200, res.code);
}

Checklist

Not all of these might apply to your change but the more you are able to check the easier it will be to get your contribution merged.

aryanbdps9 commented 2 years ago

When I try to build gtest, it fails in the autoreconf -i step:

<project-root>/vendor/gtest-1.7.0$ autoreconf -i
Makefile.am:183: error: Libtool library used but 'LIBTOOL' is undefined
Makefile.am:183:   The usual way to define 'LIBTOOL' is to add 'LT_INIT'
Makefile.am:183:   to 'configure.ac' and run 'aclocal' and 'autoconf' again.
Makefile.am:183:   If 'LT_INIT' is in 'configure.ac', make sure
Makefile.am:183:   its definition is in aclocal's search path.
autoreconf: automake failed with exit status: 1

P.S.: I tried with this change on our client code. It's working.

aryanbdps9 commented 2 years ago

This example shows a sample use case of calling SSL_CTX_set_default_verify_paths (although it's boost, but I hope you get the idea).