From 25ee96c5042888d339d07886efc0426e8e005bde Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Tue, 28 Oct 2008 16:31:12 +0000 Subject: [PATCH] - fix curl anonymous id header - rename the header name to make it a little bit shorter --- zypp/media/MediaAria2c.cc | 4 ++-- zypp/media/MediaCurl.cc | 34 +++++++++++++++++++--------------- zypp/media/MediaCurl.h | 1 + 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/zypp/media/MediaAria2c.cc b/zypp/media/MediaAria2c.cc index 0f5324d..dadf40a 100644 --- a/zypp/media/MediaAria2c.cc +++ b/zypp/media/MediaAria2c.cc @@ -98,12 +98,12 @@ const char *const MediaAria2c::anonymousIdHeader() static const std::string _value( str::form( - "X-ZYpp-AnonymousUniqueId: %s", + "X-Zypp-AnonymousId: %s", target ? target->anonymousUniqueId().c_str() : "" ) ); return _value.c_str(); } - + const char *const MediaAria2c::agentString() { // we need to add the release and identifier to the diff --git a/zypp/media/MediaCurl.cc b/zypp/media/MediaCurl.cc index 85a6f56..7c3cf3c 100644 --- a/zypp/media/MediaCurl.cc +++ b/zypp/media/MediaCurl.cc @@ -203,9 +203,9 @@ const char *const MediaCurl::anonymousIdHeader() } static const std::string _value( - str::form( - "X-ZYpp-AnonymousUniqueId: %s", - target ? target->anonymousUniqueId().c_str() : "" ) + str::trim( str::form( + "X-ZYpp-AnonymousId: %s", + target ? target->anonymousUniqueId().c_str() : "" ) ) ); return _value.c_str(); } @@ -244,7 +244,8 @@ MediaCurl::MediaCurl( const Url & url_r, : MediaHandler( url_r, attach_point_hint_r, "/", // urlpath at attachpoint true ), // does_download - _curl( NULL ) + _curl( NULL ), + _customHeaders(0L) { _curlError[0] = '\0'; _curlDebug = 0L; @@ -491,18 +492,7 @@ void MediaCurl::attachTo (bool next) disconnectFrom(); ZYPP_THROW(MediaCurlSetOptException(_url, _curlError)); } - - // now add the anonymous id header - curl_slist *chunk = NULL; - chunk = curl_slist_append(chunk, anonymousIdHeader()); - ret = curl_easy_setopt ( _curl, CURLOPT_HTTPHEADER, chunk ); - curl_slist_free_all(chunk); - if ( ret != 0) { - disconnectFrom(); - ZYPP_THROW(MediaCurlSetOptException(_url, _curlError)); - } - } @@ -714,6 +704,14 @@ void MediaCurl::attachTo (bool next) ZYPP_THROW(MediaCurlSetOptException(_url, _curlError)); } + // now add the anonymous id header + _customHeaders = curl_slist_append(_customHeaders, anonymousIdHeader()); + ret = curl_easy_setopt ( _curl, CURLOPT_HTTPHEADER, _customHeaders ); + + if ( ret != 0) { + disconnectFrom(); + ZYPP_THROW(MediaCurlSetOptException(_url, _curlError)); + } // FIXME: need a derived class to propelly compare url's MediaSourceRef media( new MediaSource(_url.getScheme(), _url.asString())); @@ -734,6 +732,12 @@ MediaCurl::checkAttachPoint(const Pathname &apoint) const // void MediaCurl::disconnectFrom() { + if ( _customHeaders ) + { + curl_slist_free_all(_customHeaders); + _customHeaders = 0L; + } + if ( _curl ) { curl_easy_cleanup( _curl ); diff --git a/zypp/media/MediaCurl.h b/zypp/media/MediaCurl.h index 6a45a70..9a0f22b 100644 --- a/zypp/media/MediaCurl.h +++ b/zypp/media/MediaCurl.h @@ -114,6 +114,7 @@ class MediaCurl : public MediaHandler { CURL *_curl; char _curlError[ CURL_ERROR_SIZE ]; long _curlDebug; + curl_slist *_customHeaders; mutable std::string _userpwd; std::string _proxy; -- 2.7.4