https://issues.shibboleth.net/jira/browse/SSPCPP-337
authorScott Cantor <cantor.2@osu.edu>
Mon, 17 Jan 2011 00:31:39 +0000 (00:31 +0000)
committerScott Cantor <cantor.2@osu.edu>
Mon, 17 Jan 2011 00:31:39 +0000 (00:31 +0000)
xmltooling/soap/impl/CURLSOAPTransport.cpp
xmltooling/util/CurlURLInputStream.cpp

index a5fb29a..0cf2d0f 100644 (file)
@@ -87,8 +87,9 @@ namespace xmltooling {
 
         virtual ~CURLSOAPTransport() {
             curl_slist_free_all(m_headers);
-            curl_easy_setopt(m_handle,CURLOPT_ERRORBUFFER,nullptr);
-            curl_easy_setopt(m_handle,CURLOPT_PRIVATE,m_authenticated ? "secure" : nullptr); // Save off security "state".
+            curl_easy_setopt(m_handle, CURLOPT_USERAGENT, nullptr);
+            curl_easy_setopt(m_handle, CURLOPT_ERRORBUFFER, nullptr);
+            curl_easy_setopt(m_handle, CURLOPT_PRIVATE, m_authenticated ? "secure" : nullptr); // Save off security "state".
             g_CURLPool->put(m_sender.c_str(), m_peerName.c_str(), m_endpoint.c_str(), m_handle);
         }
 
@@ -204,6 +205,7 @@ namespace xmltooling {
         CURL* m_handle;
         stringstream m_stream;
         struct curl_slist* m_headers;
+               string m_useragent;
         map<string,vector<string> > m_response_headers;
         vector<string> m_saved_options;
 #ifndef XMLTOOLING_NO_XMLSEC
@@ -323,11 +325,6 @@ CURL* CURLPool::get(const SOAPTransport::Address& addr)
     curl_easy_setopt(handle,CURLOPT_HEADERFUNCTION,&curl_header_hook);
     curl_easy_setopt(handle,CURLOPT_WRITEFUNCTION,&curl_write_hook);
     curl_easy_setopt(handle,CURLOPT_DEBUGFUNCTION,&curl_debug_hook);
-    string ua = XMLToolingConfig::getConfig().user_agent;
-    if (!ua.empty()) {
-        ua = ua + " libcurl/" + LIBCURL_VERSION + ' ' + OPENSSL_VERSION_TEXT;
-        curl_easy_setopt(handle, CURLOPT_USERAGENT, ua.c_str());
-    }
     return handle;
 }
 
@@ -538,6 +535,12 @@ void CURLSOAPTransport::send(istream* in)
         m_headers = curl_slist_append(m_headers, hdr.c_str());
     }
 
+    m_useragent = XMLToolingConfig::getConfig().user_agent;
+    if (!m_useragent.empty()) {
+        m_useragent = m_useragent + " libcurl/" + LIBCURL_VERSION + ' ' + OPENSSL_VERSION_TEXT;
+        curl_easy_setopt(m_handle, CURLOPT_USERAGENT, m_useragent.c_str());
+    }
+
     // Set request headers.
     curl_easy_setopt(m_handle,CURLOPT_HTTPHEADER,m_headers);
 
index 5526024..6d54cf0 100644 (file)
@@ -273,12 +273,6 @@ void CurlURLInputStream::init(const DOMElement* e)
     curl_easy_setopt(fEasy, CURLOPT_NOSIGNAL, 1);
     curl_easy_setopt(fEasy, CURLOPT_FAILONERROR, 1);
     curl_easy_setopt(fEasy, CURLOPT_ENCODING, "");
-    string ua = XMLToolingConfig::getConfig().user_agent;
-    if (!ua.empty()) {
-        ua = ua + " libcurl/" + LIBCURL_VERSION + ' ' + OPENSSL_VERSION_TEXT;
-        curl_easy_setopt(fEasy, CURLOPT_USERAGENT, ua.c_str());
-    }
-
 
     // Install SSL callback.
     curl_easy_setopt(fEasy, CURLOPT_SSL_CTX_FUNCTION, ssl_ctx_callback);
@@ -292,13 +286,21 @@ void CurlURLInputStream::init(const DOMElement* e)
         // Outgoing tag.
         if (!fCacheTag->empty()) {
             fHeaders = curl_slist_append(fHeaders, fCacheTag->c_str());
-            curl_easy_setopt(fEasy, CURLOPT_HTTPHEADER, fHeaders);
         }
         // Incoming tag.
         curl_easy_setopt(fEasy, CURLOPT_HEADERFUNCTION, curl_header_hook);
         curl_easy_setopt(fEasy, CURLOPT_HEADERDATA, fCacheTag);
     }
 
+    // Add User-Agent as a header for now. TODO: Add private member to hold the
+    // value for the standard UA option.
+    string ua = string("User-Agent: ") + XMLToolingConfig::getConfig().user_agent +
+        " libcurl/" + LIBCURL_VERSION + ' ' + OPENSSL_VERSION_TEXT;
+    fHeaders = curl_slist_append(fHeaders, ua.c_str());
+
+    // Add User-Agent and cache headers.
+    curl_easy_setopt(fEasy, CURLOPT_HTTPHEADER, fHeaders);
+
     if (e) {
         const XMLCh* flag = e->getAttributeNS(nullptr, verifyHost);
         if (flag && (*flag == chLatin_f || *flag == chDigit_0))