billowqiu commented on a change in pull request #13112:
URL: https://github.com/apache/pulsar/pull/13112#discussion_r761704364
##########
File path: pulsar-client-cpp/lib/HTTPLookupService.cc
##########
@@ -148,132 +148,148 @@ void
HTTPLookupService::handleNamespaceTopicsHTTPRequest(NamespaceTopicsPromise
}
}
-Result HTTPLookupService::sendHTTPRequest(const std::string completeUrl,
std::string &responseData) {
- CURL *handle;
- CURLcode res;
- std::string version = std::string("Pulsar-CPP-v") +
_PULSAR_VERSION_INTERNAL_;
- handle = curl_easy_init();
-
- if (!handle) {
- LOG_ERROR("Unable to curl_easy_init for url " << completeUrl);
- // No curl_easy_cleanup required since handle not initialized
- return ResultLookupError;
- }
- // set URL
- curl_easy_setopt(handle, CURLOPT_URL, completeUrl.c_str());
-
- // Write callback
- curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, curlWriteCallback);
- curl_easy_setopt(handle, CURLOPT_WRITEDATA, &responseData);
+Result HTTPLookupService::sendHTTPRequest(std::string completeUrl, std::string
&responseData) {
+ uint16_t reqCount = 0;
+ Result retResult = ResultOk;
+ while(++reqCount <= MAX_HTTP_REDIRECTS) {
+ CURL *handle;
+ CURLcode res;
+ std::string version = std::string("Pulsar-CPP-v") +
_PULSAR_VERSION_INTERNAL_;
+ handle = curl_easy_init();
+
+ if (!handle) {
+ LOG_ERROR("Unable to curl_easy_init for url " << completeUrl);
+ // No curl_easy_cleanup required since handle not initialized
+ return ResultLookupError;
+ }
+ // set URL
+ curl_easy_setopt(handle, CURLOPT_URL, completeUrl.c_str());
- // New connection is made for each call
- curl_easy_setopt(handle, CURLOPT_FRESH_CONNECT, 1L);
- curl_easy_setopt(handle, CURLOPT_FORBID_REUSE, 1L);
+ // Write callback
+ curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, curlWriteCallback);
+ curl_easy_setopt(handle, CURLOPT_WRITEDATA, &responseData);
- // Skipping signal handling - results in timeouts not honored during the
DNS lookup
- curl_easy_setopt(handle, CURLOPT_NOSIGNAL, 1L);
+ // New connection is made for each call
+ curl_easy_setopt(handle, CURLOPT_FRESH_CONNECT, 1L);
+ curl_easy_setopt(handle, CURLOPT_FORBID_REUSE, 1L);
- // Timer
- curl_easy_setopt(handle, CURLOPT_TIMEOUT, lookupTimeoutInSeconds_);
+ // Skipping signal handling - results in timeouts not honored during
the DNS lookup
+ curl_easy_setopt(handle, CURLOPT_NOSIGNAL, 1L);
- // Set User Agent
- curl_easy_setopt(handle, CURLOPT_USERAGENT, version.c_str());
+ // Timer
+ curl_easy_setopt(handle, CURLOPT_TIMEOUT, lookupTimeoutInSeconds_);
- // Redirects
- curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1L);
- curl_easy_setopt(handle, CURLOPT_MAXREDIRS, MAX_HTTP_REDIRECTS);
+ // Set User Agent
+ curl_easy_setopt(handle, CURLOPT_USERAGENT, version.c_str());
- // Fail if HTTP return code >=400
- curl_easy_setopt(handle, CURLOPT_FAILONERROR, 1L);
+ // Redirects
+ // curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1L);
+ // curl_easy_setopt(handle, CURLOPT_MAXREDIRS, MAX_HTTP_REDIRECTS);
Review comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]