Mercurial > hg > orthanc
changeset 469:a6fe16a31615
transmitting credentials by copy
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 12 Jul 2013 15:36:59 +0200 |
parents | 456b9d2e9af4 |
children | 63b515853299 |
files | OrthancCppClient/HttpClient.cpp OrthancCppClient/HttpClient.h |
diffstat | 2 files changed, 37 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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() {
--- 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> 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();