eden/fs/store/mononoke/CurlHttpClient.cpp
/// Makes an HTTP GET request to the given path.
Makes an HTTP GET request to the given path.
Makes an HTTP GET request to the given path .
std::unique_ptr<folly::IOBuf> CurlHttpClient::get(folly::StringPiece path) {
  auto buffer = folly::IOBufQueue{};
  if (curl_easy_setopt(handle_.get(), CURLOPT_WRITEDATA, &buffer) != CURLE_OK) {
    throw std::runtime_error("curl failed to set CURLOPT_WRITEDATA");
  }
  auto url = buildAddress(path);
  if (curl_easy_setopt(handle_.get(), CURLOPT_URL, url.c_str()) != CURLE_OK) {
    throw std::runtime_error(
        folly::to<std::string>("curl failed to set url: ", url));
  }
  auto ret = curl_easy_perform(handle_.get());
  if (ret != CURLE_OK) {
    address_.reset();
    throw std::runtime_error(folly::to<std::string>(
        "curl error: while fetching ",
        path,
        " code: ",
        curl_easy_strerror(ret)));
  }
  long statusCode;
  if (curl_easy_getinfo(handle_.get(), CURLINFO_RESPONSE_CODE, &statusCode) !=
      CURLE_OK) {
    throw std::runtime_error("curl failed to get response code");
  }
  if (statusCode != 200) {
    throw std::runtime_error(folly::to<std::string>(
        "received ",
        statusCode,
        " error when fetching '",
        path,
        "' to Mononoke API Server"));
  }
  auto result = buffer.move();
  if (!result) {
    return std::make_unique<folly::IOBuf>();
  }
  result->coalesce();
  return result;
}
std :: unique_ptr < folly :: IOBuf > CurlHttpClient :: get ( folly :: StringPiece path ) { auto buffer = folly :: IOBufQueue { } ; if ( curl_easy_setopt ( handle_ . get ( ) , CURLOPT_WRITEDATA , & buffer ) != CURLE_OK ) { throw std :: runtime_error ( " " ) ; } auto url = buildAddress ( path ) ; if ( curl_easy_setopt ( handle_ . get ( ) , CURLOPT_URL , url . c_str ( ) ) != CURLE_OK ) { throw std :: runtime_error ( folly :: to < std :: string > ( " " , url ) ) ; } auto ret = curl_easy_perform ( handle_ . get ( ) ) ; if ( ret != CURLE_OK ) { address_ . reset ( ) ; throw std :: runtime_error ( folly :: to < std :: string > ( " " , path , " " , curl_easy_strerror ( ret ) ) ) ; } long statusCode ; if ( curl_easy_getinfo ( handle_ . get ( ) , CURLINFO_RESPONSE_CODE , & statusCode ) != CURLE_OK ) { throw std :: runtime_error ( " " ) ; } if ( statusCode != 200 ) { throw std :: runtime_error ( folly :: to < std :: string > ( " " , statusCode , " " , path , " " ) ) ; } auto result = buffer . move ( ) ; if ( ! result ) { return std :: make_unique < folly :: IOBuf > ( ) ; } result -> coalesce ( ) ; return result ; }
Makes an HTTP GET request to the given path.
Makes an HTTP GET request to the given path .
// make sure the caller of this function gets the response in one piece