@@ -17,17 +17,16 @@ namespace duckdb {
1717// place curl will look. But not every distro has this file in the same location, so we search a
1818// number of common locations and use the first one we find.
1919static std::string certFileLocations[] = {
20- // Arch, Debian-based, Gentoo
21- " /etc/ssl/certs/ca-certificates.crt" ,
22- // RedHat 7 based
23- " /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem" ,
24- // Redhat 6 based
25- " /etc/pki/tls/certs/ca-bundle.crt" ,
26- // OpenSUSE
27- " /etc/ssl/ca-bundle.pem" ,
28- // Alpine
29- " /etc/ssl/cert.pem" };
30-
20+ // Arch, Debian-based, Gentoo
21+ " /etc/ssl/certs/ca-certificates.crt" ,
22+ // RedHat 7 based
23+ " /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem" ,
24+ // Redhat 6 based
25+ " /etc/pki/tls/certs/ca-bundle.crt" ,
26+ // OpenSUSE
27+ " /etc/ssl/ca-bundle.pem" ,
28+ // Alpine
29+ " /etc/ssl/cert.pem" };
3130
3231// ! Grab the first path that exists, from a list of well-known locations
3332static std::string SelectCURLCertPath () {
@@ -44,15 +43,15 @@ static std::string cert_path = SelectCURLCertPath();
4443
4544static size_t RequestWriteCallback (void *contents, size_t size, size_t nmemb, void *userp) {
4645 size_t totalSize = size * nmemb;
47- std::string* str = static_cast <std::string*>(userp);
48- str->append (static_cast <char *>(contents), totalSize);
46+ std::string * str = static_cast <std::string *>(userp);
47+ str->append (static_cast <char *>(contents), totalSize);
4948 return totalSize;
5049}
5150
5251static size_t RequestHeaderCallback (void *contents, size_t size, size_t nmemb, void *userp) {
5352 size_t totalSize = size * nmemb;
54- std::string header (static_cast <char *>(contents), totalSize);
55- HeaderCollector* header_collection = static_cast <HeaderCollector*>(userp);
53+ std::string header (static_cast <char *>(contents), totalSize);
54+ HeaderCollector * header_collection = static_cast <HeaderCollector *>(userp);
5655
5756 // Trim trailing \r\n
5857 if (!header.empty () && header.back () == ' \n ' ) {
@@ -86,7 +85,7 @@ static size_t RequestHeaderCallback(void *contents, size_t size, size_t nmemb, v
8685 return totalSize;
8786}
8887
89- CURLHandle::CURLHandle (const string &token, const string &cert_path) {
88+ CURLHandle::CURLHandle (const string &token, const string &cert_path) {
9089 curl = curl_easy_init ();
9190 if (!curl) {
9291 throw InternalException (" Failed to initialize curl" );
@@ -104,15 +103,13 @@ CURLHandle::~CURLHandle() {
104103 curl_easy_cleanup (curl);
105104}
106105
107-
108106struct RequestInfo {
109107 string url = " " ;
110108 string body = " " ;
111109 uint16_t response_code = 0 ;
112110 std::vector<HTTPHeaders> header_collection;
113111};
114112
115-
116113static idx_t httpfs_client_count = 0 ;
117114
118115class HTTPFSCurlClient : public HTTPClient {
@@ -140,11 +137,12 @@ class HTTPFSCurlClient : public HTTPClient {
140137 }
141138
142139 if (http_params.enable_curl_server_cert_verification ) {
143- curl_easy_setopt (*curl, CURLOPT_SSL_VERIFYPEER, 1L ); // Verify the cert
144- curl_easy_setopt (*curl, CURLOPT_SSL_VERIFYHOST, 2L ); // Verify that the cert matches the hostname
140+ curl_easy_setopt (*curl, CURLOPT_SSL_VERIFYPEER, 1L ); // Verify the cert
141+ curl_easy_setopt (*curl, CURLOPT_SSL_VERIFYHOST, 2L ); // Verify that the cert matches the hostname
145142 } else {
146- curl_easy_setopt (*curl, CURLOPT_SSL_VERIFYPEER, 0L ); // Override default, don't verify the cert
147- curl_easy_setopt (*curl, CURLOPT_SSL_VERIFYHOST, 0L ); // Override default, don't verify that the cert matches the hostname
143+ curl_easy_setopt (*curl, CURLOPT_SSL_VERIFYPEER, 0L ); // Override default, don't verify the cert
144+ curl_easy_setopt (*curl, CURLOPT_SSL_VERIFYHOST,
145+ 0L ); // Override default, don't verify that the cert matches the hostname
148146 }
149147
150148 // set read timeout
@@ -164,7 +162,8 @@ class HTTPFSCurlClient : public HTTPClient {
164162 curl_easy_setopt (*curl, CURLOPT_WRITEDATA, &request_info->body );
165163
166164 if (!http_params.http_proxy .empty ()) {
167- curl_easy_setopt (*curl, CURLOPT_PROXY, StringUtil::Format (" %s:%s" , http_params.http_proxy , http_params.http_proxy_port ).c_str ());
165+ curl_easy_setopt (*curl, CURLOPT_PROXY,
166+ StringUtil::Format (" %s:%s" , http_params.http_proxy , http_params.http_proxy_port ).c_str ());
168167
169168 if (!http_params.http_proxy_username .empty ()) {
170169 curl_easy_setopt (*curl, CURLOPT_PROXYUSERNAME, http_params.http_proxy_username .c_str ());
@@ -201,7 +200,8 @@ class HTTPFSCurlClient : public HTTPClient {
201200 curl_easy_getinfo (*curl, CURLINFO_RESPONSE_CODE, &request_info->response_code );
202201
203202 idx_t bytes_received = 0 ;
204- if (!request_info->header_collection .empty () && request_info->header_collection .back ().HasHeader (" content-length" )) {
203+ if (!request_info->header_collection .empty () &&
204+ request_info->header_collection .back ().HasHeader (" content-length" )) {
205205 bytes_received = std::stoi (request_info->header_collection .back ().GetHeaderValue (" content-length" ));
206206 D_ASSERT (bytes_received == request_info->body .size ());
207207 } else {
@@ -211,9 +211,9 @@ class HTTPFSCurlClient : public HTTPClient {
211211 state->total_bytes_received += bytes_received;
212212 }
213213
214- const char * data = request_info->body .c_str ();
214+ const char * data = request_info->body .c_str ();
215215 if (info.content_handler ) {
216- info.content_handler (const_data_ptr_cast (data), bytes_received);
216+ info.content_handler (const_data_ptr_cast (data), bytes_received);
217217 }
218218
219219 return TransformResponseCurl (res);
@@ -321,7 +321,7 @@ class HTTPFSCurlClient : public HTTPClient {
321321
322322 // Get HTTP response status code
323323 curl_easy_getinfo (*curl, CURLINFO_RESPONSE_CODE, &request_info->response_code );
324- return TransformResponseCurl ( res);
324+ return TransformResponseCurl (res);
325325 }
326326
327327 unique_ptr<HTTPResponse> Post (PostRequestInfo &info) override {
@@ -359,7 +359,7 @@ class HTTPFSCurlClient : public HTTPClient {
359359 curl_easy_getinfo (*curl, CURLINFO_RESPONSE_CODE, &request_info->response_code );
360360 info.buffer_out = request_info->body ;
361361 // Construct HTTPResponse
362- return TransformResponseCurl ( res);
362+ return TransformResponseCurl (res);
363363 }
364364
365365private:
@@ -406,15 +406,16 @@ class HTTPFSCurlClient : public HTTPClient {
406406 auto response = make_uniq<HTTPResponse>(status_code);
407407 if (res != CURLcode::CURLE_OK) {
408408 // TODO: request error can come from HTTPS Status code toString() value.
409- if (!request_info->header_collection .empty () && request_info->header_collection .back ().HasHeader (" __RESPONSE_STATUS__" )) {
409+ if (!request_info->header_collection .empty () &&
410+ request_info->header_collection .back ().HasHeader (" __RESPONSE_STATUS__" )) {
410411 response->request_error = request_info->header_collection .back ().GetHeaderValue (" __RESPONSE_STATUS__" );
411412 } else {
412413 response->request_error = curl_easy_strerror (res);
413414 }
414415 return response;
415416 }
416417 response->body = request_info->body ;
417- response->url = request_info->url ;
418+ response->url = request_info->url ;
418419 if (!request_info->header_collection .empty ()) {
419420 for (auto &header : request_info->header_collection .back ()) {
420421 response->headers .Insert (header.first , header.second );
@@ -465,7 +466,8 @@ unordered_map<string, string> HTTPFSCurlUtil::ParseGetParameters(const string &t
465466 unordered_map<std::string, std::string> params;
466467
467468 auto pos = text.find (' ?' );
468- if (pos == std::string::npos) return params;
469+ if (pos == std::string::npos)
470+ return params;
469471
470472 std::string query = text.substr (pos + 1 );
471473 std::stringstream ss (query);
@@ -478,7 +480,7 @@ unordered_map<string, string> HTTPFSCurlUtil::ParseGetParameters(const string &t
478480 std::string value = StringUtil::URLDecode (item.substr (eq_pos + 1 ));
479481 params[key] = value;
480482 } else {
481- params[item] = " " ; // key with no value
483+ params[item] = " " ; // key with no value
482484 }
483485 }
484486
0 commit comments