# HG changeset patch # User Sebastien Jodogne # Date 1373636219 -7200 # Node ID a6fe16a31615759027b7d431efcffd7c1f78a362 # Parent 456b9d2e9af43cd13abf3de51ee1269a129664fb transmitting credentials by copy diff -r 456b9d2e9af4 -r a6fe16a31615 OrthancCppClient/HttpClient.cpp --- a/OrthancCppClient/HttpClient.cpp Fri Jul 12 14:53:17 2013 +0200 +++ b/OrthancCppClient/HttpClient.cpp Fri Jul 12 15:36:59 2013 +0200 @@ -44,7 +44,7 @@ { if (code != CURLE_OK) { - printf("ICI: %s\n", curl_easy_strerror(code)); + //printf("ICI: %s\n", curl_easy_strerror(code)); throw HttpException("CURL: " + std::string(curl_easy_strerror(code))); } @@ -69,7 +69,7 @@ } - HttpClient::HttpClient() : pimpl_(new PImpl) + void HttpClient::Setup() { pimpl_->postHeaders_ = NULL; if ((pimpl_->postHeaders_ = curl_slist_append(pimpl_->postHeaders_, "Expect:")) == NULL) @@ -104,6 +104,28 @@ } + HttpClient::HttpClient() : pimpl_(new PImpl) + { + Setup(); + } + + + HttpClient::HttpClient(const HttpClient& other) : pimpl_(new PImpl) + { + Setup(); + + if (other.IsVerbose()) + { + SetVerbose(true); + } + + if (other.credentials_.size() != 0) + { + credentials_ = other.credentials_; + } + } + + HttpClient::~HttpClient() { curl_easy_cleanup(pimpl_->curl_); @@ -133,6 +155,11 @@ CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_WRITEDATA, &answer)); CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPHEADER, NULL)); + if (credentials_.size() != 0) + { + CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_USERPWD, credentials_.c_str())); + } + switch (method_) { case Orthanc_HttpMethod_Get: @@ -207,11 +234,9 @@ void HttpClient::SetCredentials(const char* username, const char* password) { - std::string s = std::string(username) + ":" + std::string(password); - CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_USERPWD, s.c_str())); + credentials_ = std::string(username) + ":" + std::string(password); } - void HttpClient::GlobalInitialize() { diff -r 456b9d2e9af4 -r a6fe16a31615 OrthancCppClient/HttpClient.h --- a/OrthancCppClient/HttpClient.h Fri Jul 12 14:53:17 2013 +0200 +++ b/OrthancCppClient/HttpClient.h Fri Jul 12 15:36:59 2013 +0200 @@ -43,12 +43,19 @@ boost::shared_ptr pimpl_; std::string url_; + std::string credentials_; Orthanc_HttpMethod method_; Orthanc_HttpStatus lastStatus_; std::string postData_; bool isVerbose_; + void Setup(); + + void operator= (const HttpClient&); // Forbidden + public: + HttpClient(const HttpClient& base); + HttpClient(); ~HttpClient();