Bugfix: Curl appends rather than overrites writedata buff, so we need to copy and...
authorBjoern Sikora <bjoern.sikora@intra2net.com>
Fri, 9 Oct 2009 15:27:47 +0000 (17:27 +0200)
committerBjoern Sikora <bjoern.sikora@intra2net.com>
Fri, 9 Oct 2009 15:27:47 +0000 (17:27 +0200)
src/httphelper.cpp
src/httphelper.h

index f5082b4..8f7d183 100644 (file)
@@ -69,16 +69,22 @@ long HTTPHelper::http_get(const string& url)
     if ( (curl_err_code = curl_easy_perform(CurlEasyHandle) ) != 0 )
     {
         Log->print_curl_error(url,curl_err_code,CurlErrBuff);
+        CurlWritedataBuff.clear();
         return -1;
     }
     if ( (curl_err_code = curl_easy_getinfo(CurlEasyHandle,CURLINFO_RESPONSE_CODE,&curl_info)) != 0 )
     {
         Log->print_curl_error(url,curl_err_code);
+        CurlWritedataBuff.clear();
         return -1;
     }
 
     Log->print_curl_data(CurlWritedataBuff);
 
+    // Copy the received data received via curl from the curl data buffer member to the received data member. This is needed because curl appends data to the buffer rather than overrites it.
+    ReceivedCurlData = CurlWritedataBuff;
+    CurlWritedataBuff.clear();
+
     // Operation performed without any problems so we can return the curl_info
     return curl_info;
 }
@@ -90,7 +96,7 @@ long HTTPHelper::http_get(const string& url)
  */
 string HTTPHelper::get_curl_data() const
 {
-    return CurlWritedataBuff;
+    return ReceivedCurlData;
 }
 
 
index 09701d0..bbec3ec 100644 (file)
@@ -26,6 +26,7 @@ private:
     int ProxyPort;
     CURL* CurlEasyHandle;
     std::string CurlWritedataBuff;
+    std::string ReceivedCurlData;
     char CurlErrBuff[CURL_ERROR_SIZE];
 
     void set_curl_url(const std::string& url);