diff OrthancCppClient/HttpClient.cpp @ 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 c9a5d72f8481
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()
   {