52 if ( o_url.empty() ) {
53 MIL <<
"Url list is empty" << std::endl;
57 std::optional<MediaUrl> primary;
58 std::vector<MediaUrl> resolved;
59 std::optional<MediaHandlerFactory::MediaHandlerType> hdlType;
60 std::for_each( o_url.begin (), o_url.end(), [&](
const MediaUrl &u ){
62 if( !u.url().isValid() ) {
63 MIL <<
"Url is not valid" << std::endl;
64 ZYPP_THROW(MediaBadUrlException(u.url()));
68 if ( u.hasConfig(
"http-headers") )
72 MIL <<
"Trying scheme '" <<
url.getScheme() <<
"'" << std::endl;
80 else if ( myHdlType != hdlType ) {
83 MIL <<
"Different handler type than primary URL, ignoring" << std::endl;
87 MediaUrl newUrl(
url, u.config()) ;
88 if ( !custom_headers.empty () ) {
89 newUrl.setConfig (
"http-headers", std::move(custom_headers) );
95 resolved.push_back (std::move(newUrl));
104 if ( resolved.size() > 1 && *hdlType != MediaCURLType )
105 ERR <<
"Got mirrors for handler type: " << *hdlType <<
" they will be ignored!" << std::endl;
107 std::unique_ptr<MediaHandler> _handler;
110 _handler = std::make_unique<MediaCD> (*primary,preferred_attach_point);
114 _handler = std::make_unique<MediaNFS> (*primary,preferred_attach_point);
118 _handler = std::make_unique<MediaISO> (*primary,preferred_attach_point);
121 case MediaFileType: {
122 _handler = std::make_unique<MediaDIR> (*primary,preferred_attach_point);
125 case MediaDISKType: {
126 _handler = std::make_unique<MediaDISK> (*primary,preferred_attach_point);
129 case MediaCIFSType: {
130 _handler = std::make_unique<MediaCIFS> (*primary,preferred_attach_point);
133 case MediaCURLType: {
134 enum WhichHandler { choose, curl, curl2 };
135 WhichHandler which = choose;
137 if (
const std::string & queryparam = primary->url().getQueryParam(
"mediahandler"); ! queryparam.empty() ) {
138 if ( queryparam ==
"curl" )
140 else if ( queryparam ==
"curl2" )
142 else if ( queryparam ==
"network" || queryparam ==
"multicurl" )
145 WAR <<
"Unknown mediahandler='" << queryparam <<
"' in URL; Choosing the default" << std::endl;
148 if ( which == choose ) {
150 if ( indeterminate(envstate) ) {
151#if APIConfig(LIBZYPP_CONFIG_USE_LEGACY_CURL_BACKEND_BY_DEFAULT)
157 which = bool(envstate) ? curl2 : curl;
161 std::unique_ptr<MediaNetworkCommonHandler> handler;
165 handler = std::make_unique<MediaCurl2>( *primary, resolved, preferred_attach_point );
168 handler = std::make_unique<MediaCurl>( *primary, resolved, preferred_attach_point );
171 _handler = std::move(handler);
174 case MediaPluginType: {
189 ERR <<
"Failed to create media handler" << std::endl;
193 MIL <<
"Opened: " << *_handler << std::endl;