@@ -41,18 +41,26 @@ extern "C" size_t CurlOnWriteData(char* ptr, size_t size, size_t nmemb,
4141 return size * nmemb;
4242}
4343
44+ struct CurlPtrCleanup {
45+ void operator ()(CURL* arg) const { return curl_easy_cleanup (arg); }
46+ };
47+
48+ struct CurlSListFreeAll {
49+ void operator ()(curl_slist* arg) const { return curl_slist_free_all (arg); }
50+ };
51+
4452google::cloud::StatusOr<std::string> HttpGet (std::string const & url,
4553 std::string const & token) {
4654 static auto const kCurlInit = [] {
4755 return curl_global_init (CURL_GLOBAL_ALL);
4856 }();
4957 (void )kCurlInit ;
5058 auto const authorization = " Authorization: Bearer " + token;
51- using Headers = std::unique_ptr<curl_slist, decltype (&curl_slist_free_all) >;
52- auto const headers = Headers{
53- curl_slist_append (nullptr , authorization.c_str ()), curl_slist_free_all };
54- using CurlHandle = std::unique_ptr<CURL, decltype (&curl_easy_cleanup) >;
55- auto curl = CurlHandle (curl_easy_init (), curl_easy_cleanup );
59+ using Headers = std::unique_ptr<curl_slist, CurlSListFreeAll >;
60+ auto const headers =
61+ Headers{ curl_slist_append (nullptr , authorization.c_str ())};
62+ using CurlHandle = std::unique_ptr<CURL, CurlPtrCleanup >;
63+ auto curl = CurlHandle (curl_easy_init ());
5664 if (!curl) throw std::runtime_error (" Failed to create CurlHandle" );
5765 std::string buffer;
5866 curl_easy_setopt (curl.get (), CURLOPT_URL, url.c_str ());
0 commit comments