diff --git a/cli/zerotier.cpp b/cli/zerotier.cpp index f9eb4716b..f9eec5d08 100644 --- a/cli/zerotier.cpp +++ b/cli/zerotier.cpp @@ -159,9 +159,9 @@ static size_t _curlStringAppendCallback(void *contents,size_t size,size_t nmemb, static std::tuple GET(const CLIState &state,const std::map &headers,const std::string &url) { - int status = -1; std::string body; char errbuf[CURL_ERROR_SIZE]; + char urlbuf[4096]; CURL *curl = curl_easy_init(); if (!curl) { @@ -174,6 +174,20 @@ static std::tuple GET(const CLIState &state,const std::map 0) ? 0L : 1L); curl_easy_setopt(curl,CURLOPT_ERRORBUFFER,errbuf); + curl_easy_setopt(curl,CURLOPT_FOLLOWLOCATION,0L); + + Utils::scopy(urlbuf,sizeof(urlbuf),url.c_str()); + curl_easy_setopt(curl,CURLOPT_URL,urlbuf); + + struct curl_slist *hdrs = (struct curl_slist *)0; + for(std::map::const_iterator i(headers.begin());i!=headers.end();++i) { + std::string htmp(i->first); + htmp.append(": "); + htmp.append(i->second); + hdrs = curl_slist_append(hdrs,htmp.c_str()); + } + if (hdrs) + curl_easy_setopt(curl,CURLOPT_HTTPHEADER,hdrs); memset(errbuf,0,sizeof(errbuf)); CURLcode res = curl_easy_perform(curl); @@ -182,9 +196,13 @@ static std::tuple GET(const CLIState &state,const std::map