gpAux/extensions/gps3ext/src/s3restful_service.cpp
// get() will execute HTTP GET RESTful API with given url/headers/params,
// and return raw response content.
//
// This method does not care about response format, caller need to handle
// response format accordingly.
get() will execute HTTP GET RESTful API with given url/headers/params,
and return raw response content.

This method does not care about response format, caller need to handle
response format accordingly.
get () will execute HTTP GET RESTful API with given url / headers / params and return raw response content . This method does not care about response format caller need to handle response format accordingly .
Response S3RESTfulService::get(const string &url, HTTPHeaders &headers,
                               const map<string, string> &params) {
    Response response;
    CURL *curl = curl_easy_init();
    CHECK_OR_DIE_MSG(curl != NULL, "%s", "Failed to create curl handler");
    headers.CreateList();
    curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
    curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 1L);
    curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers.GetList());
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&response);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, RESTfulServiceWriteFuncCallback);
    curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, s3ext_low_speed_limit);
    curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, s3ext_low_speed_time);
    map<string, string>::const_iterator iter = params.find("debug");
    if (iter != params.end() && iter->second == "true") {
        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
    }
    if (s3ext_debug_curl) {
        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
    }
    CURLcode res = curl_easy_perform(curl);
    if (res != CURLE_OK) {
        S3ERROR("curl_easy_perform() failed: %s", curl_easy_strerror(res));
        response.clearBuffers();
        response.setStatus(RESPONSE_FAIL);
        response.setMessage(string("Server connection failed: ").append(curl_easy_strerror(res)));
    } else {
        long responseCode;
        curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &responseCode);
        if (isSuccessfulResponse(responseCode)) {
            response.setStatus(RESPONSE_OK);
            response.setMessage("Success");
        } else {  
            stringstream sstr;
            sstr << "S3 server returned error, error code is " << responseCode;
            response.setStatus(RESPONSE_ERROR);
            response.setMessage(sstr.str());
        }
    }
    curl_easy_cleanup(curl);
    headers.FreeList();
    return response;
}
Response S3RESTfulService :: get ( const string & url , HTTPHeaders & headers , const map < string , string > & params ) { Response response ; CURL * curl = curl_easy_init ( ) ; CHECK_OR_DIE_MSG ( curl != NULL , " " , " " ) ; headers . CreateList ( ) ; curl_easy_setopt ( curl , CURLOPT_URL , url . c_str ( ) ) ; curl_easy_setopt ( curl , CURLOPT_FORBID_REUSE , 1L ) ; curl_easy_setopt ( curl , CURLOPT_NOSIGNAL , 1L ) ; curl_easy_setopt ( curl , CURLOPT_HTTPHEADER , headers . GetList ( ) ) ; curl_easy_setopt ( curl , CURLOPT_WRITEDATA , ( void * ) & response ) ; curl_easy_setopt ( curl , CURLOPT_WRITEFUNCTION , RESTfulServiceWriteFuncCallback ) ; curl_easy_setopt ( curl , CURLOPT_LOW_SPEED_LIMIT , s3ext_low_speed_limit ) ; curl_easy_setopt ( curl , CURLOPT_LOW_SPEED_TIME , s3ext_low_speed_time ) ; map < string , string > :: const_iterator iter = params . find ( " " ) ; if ( iter != params . end ( ) && iter -> second == " " ) { curl_easy_setopt ( curl , CURLOPT_VERBOSE , 1L ) ; } if ( s3ext_debug_curl ) { curl_easy_setopt ( curl , CURLOPT_VERBOSE , 1L ) ; } CURLcode res = curl_easy_perform ( curl ) ; if ( res != CURLE_OK ) { S3ERROR ( " " , curl_easy_strerror ( res ) ) ; response . clearBuffers ( ) ; response . setStatus ( RESPONSE_FAIL ) ; response . setMessage ( string ( " " ) . append ( curl_easy_strerror ( res ) ) ) ; } else { long responseCode ; curl_easy_getinfo ( curl , CURLINFO_RESPONSE_CODE , & responseCode ) ; if ( isSuccessfulResponse ( responseCode ) ) { response . setStatus ( RESPONSE_OK ) ; response . setMessage ( " " ) ; } else { stringstream sstr ; sstr << " " << responseCode ; response . setStatus ( RESPONSE_ERROR ) ; response . setMessage ( sstr . str ( ) ) ; } } curl_easy_cleanup ( curl ) ; headers . FreeList ( ) ; return response ; }
get() will execute HTTP GET RESTful API with given url/headers/params,
and return raw response content.
get () will execute HTTP GET RESTful API with given url / headers / params and return raw response content .
// consider low speed as timeout // Get the HTTP response status code from HTTP header // 2XX are successful response. Here we deal with 200 (OK) and 206 (partial content) // firstly. // Server error, set status to RESPONSE_ERROR