libzypp  17.36.1
request.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 ----------------------------------------------------------------------*/
13 #include <zypp-core/zyppng/base/EventDispatcher>
15 #include <zypp-core/zyppng/core/String>
16 #include <zypp-core/fs/PathInfo.h>
18 #include <zypp-curl/CurlConfig>
19 #include <zypp-curl/auth/CurlAuthData>
20 #include <zypp-media/MediaConfig>
21 #include <zypp-core/base/String.h>
22 #include <zypp-core/base/StringV.h>
23 #include <zypp-core/base/IOTools.h>
24 #include <zypp-core/Pathname.h>
25 #include <curl/curl.h>
26 #include <stdio.h>
27 #include <fcntl.h>
28 #include <utility>
29 
30 #include <iostream>
31 #include <boost/variant.hpp>
32 #include <boost/variant/polymorphic_get.hpp>
33 
34 
35 namespace zyppng {
36 
37  namespace {
38  static size_t nwr_headerCallback ( char *ptr, size_t size, size_t nmemb, void *userdata ) {
39  if ( !userdata )
40  return 0;
41 
42  NetworkRequestPrivate *that = reinterpret_cast<NetworkRequestPrivate *>( userdata );
43  return that->headerfunction( ptr, size * nmemb );
44  }
45  static size_t nwr_writeCallback ( char *ptr, size_t size, size_t nmemb, void *userdata ) {
46  if ( !userdata )
47  return 0;
48 
49  NetworkRequestPrivate *that = reinterpret_cast<NetworkRequestPrivate *>( userdata );
50  return that->writefunction( ptr, {}, size * nmemb );
51  }
52 
53  //helper for std::visit
54  template<class T> struct always_false : std::false_type {};
55  }
56 
58  : _outFile( std::move(prevState._outFile) )
59  , _downloaded( prevState._downloaded )
60  , _partialHelper( std::move(prevState._partialHelper) )
61  { }
62 
64  : _partialHelper( std::move(prevState._partialHelper) )
65  { }
66 
68  : _outFile( std::move(prevState._outFile) )
69  , _partialHelper( std::move(prevState._partialHelper) )
70  , _downloaded( prevState._downloaded )
71  { }
72 
74  : BasePrivate(p)
75  , _url ( std::move(url) )
76  , _targetFile ( std::move( targetFile) )
77  , _fMode ( std::move(fMode) )
78  , _headers( std::unique_ptr< curl_slist, decltype (&curl_slist_free_all) >( nullptr, &curl_slist_free_all ) )
79  { }
80 
82  {
83  if ( _easyHandle ) {
84  //clean up for now, later we might reuse handles
85  curl_easy_cleanup( _easyHandle );
86  //reset in request but make sure the request was not enqueued again and got a new handle
87  _easyHandle = nullptr;
88  }
89  }
90 
91  bool NetworkRequestPrivate::initialize( std::string &errBuf )
92  {
93  reset();
94 
95  if ( _easyHandle )
96  //will reset to defaults but keep live connections, session ID and DNS caches
97  curl_easy_reset( _easyHandle );
98  else
99  _easyHandle = curl_easy_init();
100  return setupHandle ( errBuf );
101  }
102 
103  bool NetworkRequestPrivate::setupHandle( std::string &errBuf )
104  {
106  curl_easy_setopt( _easyHandle, CURLOPT_ERRORBUFFER, this->_errorBuf.data() );
107 
108  const std::string urlScheme = _url.getScheme();
109  if ( urlScheme == "http" || urlScheme == "https" )
111 
112  try {
113 
114  setCurlOption( CURLOPT_PRIVATE, this );
115  setCurlOption( CURLOPT_XFERINFOFUNCTION, NetworkRequestPrivate::curlProgressCallback );
116  setCurlOption( CURLOPT_XFERINFODATA, this );
117  setCurlOption( CURLOPT_NOPROGRESS, 0L);
118  setCurlOption( CURLOPT_FAILONERROR, 1L);
119  setCurlOption( CURLOPT_NOSIGNAL, 1L);
120 
121  std::string urlBuffer( _url.asString() );
122  setCurlOption( CURLOPT_URL, urlBuffer.c_str() );
123 
124  setCurlOption( CURLOPT_WRITEFUNCTION, nwr_writeCallback );
125  setCurlOption( CURLOPT_WRITEDATA, this );
126 
128  setCurlOption( CURLOPT_CONNECT_ONLY, 1L );
129  setCurlOption( CURLOPT_FRESH_CONNECT, 1L );
130  }
132  // instead of returning no data with NOBODY, we return
133  // little data, that works with broken servers, and
134  // works for ftp as well, because retrieving only headers
135  // ftp will return always OK code ?
136  // See http://curl.haxx.se/docs/knownbugs.html #58
138  setCurlOption( CURLOPT_NOBODY, 1L );
139  else
140  setCurlOption( CURLOPT_RANGE, "0-1" );
141  }
142 
143  //make a local copy of the settings, so headers are not added multiple times
144  TransferSettings locSet = _settings;
145 
146  if ( _dispatcher ) {
147  locSet.setUserAgentString( _dispatcher->agentString().c_str() );
148 
149  // add custom headers as configured (bsc#955801)
150  const auto &cHeaders = _dispatcher->hostSpecificHeaders();
151  if ( auto i = cHeaders.find(_url.getHost()); i != cHeaders.end() ) {
152  for ( const auto &[key, value] : i->second ) {
154  "%s: %s", key.c_str(), value.c_str() )
155  ));
156  }
157  }
158  }
159 
160  locSet.addHeader("Pragma:");
161 
164  {
165  case 4: setCurlOption( CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); break;
166  case 6: setCurlOption( CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6 ); break;
167  default: break;
168  }
169 
170  setCurlOption( CURLOPT_HEADERFUNCTION, &nwr_headerCallback );
171  setCurlOption( CURLOPT_HEADERDATA, this );
172 
176  setCurlOption( CURLOPT_CONNECTTIMEOUT, locSet.connectTimeout() );
177  // If a transfer timeout is set, also set CURLOPT_TIMEOUT to an upper limit
178  // just in case curl does not trigger its progress callback frequently
179  // enough.
180  if ( locSet.timeout() )
181  {
182  setCurlOption( CURLOPT_TIMEOUT, 3600L );
183  }
184 
185  if ( urlScheme == "https" )
186  {
187  if ( :: internal::setCurlRedirProtocols ( _easyHandle ) != CURLE_OK ) {
189  }
190 
191  if( locSet.verifyPeerEnabled() ||
192  locSet.verifyHostEnabled() )
193  {
194  setCurlOption(CURLOPT_CAPATH, locSet.certificateAuthoritiesPath().c_str());
195  }
196 
197  if( ! locSet.clientCertificatePath().empty() )
198  {
199  setCurlOption(CURLOPT_SSLCERT, locSet.clientCertificatePath().c_str());
200  }
201  if( ! locSet.clientKeyPath().empty() )
202  {
203  setCurlOption(CURLOPT_SSLKEY, locSet.clientKeyPath().c_str());
204  }
205 
206 #ifdef CURLSSLOPT_ALLOW_BEAST
207  // see bnc#779177
208  setCurlOption( CURLOPT_SSL_OPTIONS, CURLSSLOPT_ALLOW_BEAST );
209 #endif
210  setCurlOption(CURLOPT_SSL_VERIFYPEER, locSet.verifyPeerEnabled() ? 1L : 0L);
211  setCurlOption(CURLOPT_SSL_VERIFYHOST, locSet.verifyHostEnabled() ? 2L : 0L);
212  // bnc#903405 - POODLE: libzypp should only talk TLS
213  setCurlOption(CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
214  }
215 
216  // follow any Location: header that the server sends as part of
217  // an HTTP header (#113275)
218  setCurlOption( CURLOPT_FOLLOWLOCATION, 1L);
219  // 3 redirects seem to be too few in some cases (bnc #465532)
220  setCurlOption( CURLOPT_MAXREDIRS, 6L );
221 
222  //set the user agent
223  setCurlOption(CURLOPT_USERAGENT, locSet.userAgentString().c_str() );
224 
225 
226  /*---------------------------------------------------------------*
227  CURLOPT_USERPWD: [user name]:[password]
228  Url::username/password -> CURLOPT_USERPWD
229  If not provided, anonymous FTP identification
230  *---------------------------------------------------------------*/
231  if ( locSet.userPassword().size() )
232  {
233  setCurlOption(CURLOPT_USERPWD, locSet.userPassword().c_str());
234  std::string use_auth = _settings.authType();
235  if (use_auth.empty())
236  use_auth = "digest,basic"; // our default
237  long auth = zypp::media::CurlAuthData::auth_type_str2long(use_auth);
238  if( auth != CURLAUTH_NONE)
239  {
240  DBG << _easyHandle << " " << "Enabling HTTP authentication methods: " << use_auth
241  << " (CURLOPT_HTTPAUTH=" << auth << ")" << std::endl;
242  setCurlOption(CURLOPT_HTTPAUTH, auth);
243  }
244  }
245 
246  if ( locSet.proxyEnabled() && ! locSet.proxy().empty() )
247  {
248  DBG << _easyHandle << " " << "Proxy: '" << locSet.proxy() << "'" << std::endl;
249  setCurlOption(CURLOPT_PROXY, locSet.proxy().c_str());
250  setCurlOption(CURLOPT_PROXYAUTH, CURLAUTH_BASIC|CURLAUTH_DIGEST|CURLAUTH_NTLM );
251 
252  /*---------------------------------------------------------------*
253  * CURLOPT_PROXYUSERPWD: [user name]:[password]
254  *
255  * Url::option(proxyuser and proxypassword) -> CURLOPT_PROXYUSERPWD
256  * If not provided, $HOME/.curlrc is evaluated
257  *---------------------------------------------------------------*/
258 
259  std::string proxyuserpwd = locSet.proxyUserPassword();
260 
261  if ( proxyuserpwd.empty() )
262  {
263  zypp::media::CurlConfig curlconf;
264  zypp::media::CurlConfig::parseConfig(curlconf); // parse ~/.curlrc
265  if ( curlconf.proxyuserpwd.empty() )
266  DBG << _easyHandle << " " << "Proxy: ~/.curlrc does not contain the proxy-user option" << std::endl;
267  else
268  {
269  proxyuserpwd = curlconf.proxyuserpwd;
270  DBG << _easyHandle << " " << "Proxy: using proxy-user from ~/.curlrc" << std::endl;
271  }
272  }
273  else
274  {
275  DBG << _easyHandle << " " << _easyHandle << " " << "Proxy: using provided proxy-user '" << _settings.proxyUsername() << "'" << std::endl;
276  }
277 
278  if ( ! proxyuserpwd.empty() )
279  {
280  setCurlOption(CURLOPT_PROXYUSERPWD, ::internal::curlUnEscape( proxyuserpwd ).c_str());
281  }
282  }
283 #if CURLVERSION_AT_LEAST(7,19,4)
284  else if ( locSet.proxy() == EXPLICITLY_NO_PROXY )
285  {
286  // Explicitly disabled in URL (see fillSettingsFromUrl()).
287  // This should also prevent libcurl from looking into the environment.
288  DBG << _easyHandle << " " << "Proxy: explicitly NOPROXY" << std::endl;
289  setCurlOption(CURLOPT_NOPROXY, "*");
290  }
291 
292 #endif
293  // else: Proxy: not explicitly set; libcurl may look into the environment
294 
296  if ( locSet.minDownloadSpeed() != 0 )
297  {
298  setCurlOption(CURLOPT_LOW_SPEED_LIMIT, locSet.minDownloadSpeed());
299  // default to 10 seconds at low speed
300  setCurlOption(CURLOPT_LOW_SPEED_TIME, 60L);
301  }
302 
303 #if CURLVERSION_AT_LEAST(7,15,5)
304  if ( locSet.maxDownloadSpeed() != 0 )
305  setCurlOption(CURLOPT_MAX_RECV_SPEED_LARGE, locSet.maxDownloadSpeed());
306 #endif
307 
309  if ( zypp::str::strToBool( _url.getQueryParam( "cookies" ), true ) )
310  setCurlOption( CURLOPT_COOKIEFILE, _currentCookieFile.c_str() );
311  else
312  MIL << _easyHandle << " " << "No cookies requested" << std::endl;
313  setCurlOption(CURLOPT_COOKIEJAR, _currentCookieFile.c_str() );
314 
315 #if CURLVERSION_AT_LEAST(7,18,0)
316  // bnc #306272
317  setCurlOption(CURLOPT_PROXY_TRANSFER_MODE, 1L );
318 #endif
319 
320  // Append settings custom headers to curl.
321  // TransferSettings assert strings are trimmed (HTTP/2 RFC 9113)
322  for ( const auto &header : locSet.headers() ) {
323  if ( !z_func()->addRequestHeader( header.c_str() ) )
325  }
326 
327  if ( _headers )
328  setCurlOption( CURLOPT_HTTPHEADER, _headers.get() );
329 
330  // set up ranges if required
332  if ( _requestedRanges.size() ) {
333 
334  std::sort( _requestedRanges.begin(), _requestedRanges.end(), []( const auto &elem1, const auto &elem2 ){
335  return ( elem1.start < elem2.start );
336  });
337 
338  CurlMultiPartHandler *helper = nullptr;
339  if ( auto initState = std::get_if<pending_t>(&_runningMode) ) {
340 
342  initState->_partialHelper = std::make_unique<CurlMultiPartHandler>(
343  multiPartMode
344  , _easyHandle
346  , *this
347  );
348  helper = initState->_partialHelper.get();
349 
350  } else if ( auto pendingState = std::get_if<prepareNextRangeBatch_t>(&_runningMode) ) {
351  helper = pendingState->_partialHelper.get();
352  } else {
353  errBuf = "Request is in invalid state to call setupHandle";
354  return false;
355  }
356 
357  if ( !helper->prepare () ) {
358  errBuf = helper->lastErrorMessage ();
359  return false;
360  }
361  }
362  }
363 
364  return true;
365 
366  } catch ( const zypp::Exception &excp ) {
367  ZYPP_CAUGHT(excp);
368  errBuf = excp.asString();
369  }
370  return false;
371  }
372 
374  {
375  auto rmode = std::get_if<NetworkRequestPrivate::running_t>( &_runningMode );
376  if ( !rmode ) {
377  DBG << _easyHandle << "Can only create output file in running mode" << std::endl;
378  return false;
379  }
380  // if we have no open file create or open it
381  if ( !rmode->_outFile ) {
382  std::string openMode = "w+b";
384  openMode = "r+b";
385 
386  rmode->_outFile = fopen( _targetFile.asString().c_str() , openMode.c_str() );
387 
388  //if the file does not exist create a new one
389  if ( !rmode->_outFile && _fMode == NetworkRequest::WriteShared ) {
390  rmode->_outFile = fopen( _targetFile.asString().c_str() , "w+b" );
391  }
392 
393  if ( !rmode->_outFile ) {
395  ,zypp::str::Format("Unable to open target file (%1%). Errno: (%2%:%3%)") % _targetFile.asString() % errno % strerr_cxx() );
396  return false;
397  }
398  }
399 
400  return true;
401  }
402 
404  {
405  // We can recover from RangeFail errors if the helper indicates it
406  auto rmode = std::get_if<NetworkRequestPrivate::running_t>( &_runningMode );
407  if ( rmode->_partialHelper ) return rmode->_partialHelper->canRecover();
408  return false;
409  }
410 
411  bool NetworkRequestPrivate::prepareToContinue( std::string &errBuf )
412  {
413  auto rmode = std::get_if<NetworkRequestPrivate::running_t>( &_runningMode );
414  if ( !rmode ) {
415  errBuf = "NetworkRequestPrivate::prepareToContinue called in invalid state";
416  return false;
417  }
418 
419  if ( rmode->_partialHelper && rmode->_partialHelper->hasMoreWork() ) {
420 
421  bool hadRangeFail = rmode->_partialHelper->lastError () == NetworkRequestError::RangeFail;
422 
423  _runningMode = prepareNextRangeBatch_t( std::move(std::get<running_t>( _runningMode )) );
424 
425  auto &prepMode = std::get<prepareNextRangeBatch_t>(_runningMode);
426  if ( !prepMode._partialHelper->prepareToContinue() ) {
427  errBuf = prepMode._partialHelper->lastErrorMessage();
428  return false;
429  }
430 
431  if ( hadRangeFail ) {
432  // we reset the handle to default values. We do this to not run into
433  // "transfer closed with outstanding read data remaining" error CURL sometimes returns when
434  // we cancel a connection because of a range error to request a smaller batch.
435  // The error will still happen but much less frequently than without resetting the handle.
436  //
437  // Note: Even creating a new handle will NOT fix the issue
438  curl_easy_reset( _easyHandle );
439  }
440  if ( !setupHandle(errBuf))
441  return false;
442 
443  return true;
444  }
445  errBuf = "Request has no more work";
446  return false;
447 
448  }
449 
451  {
452  // check if we have ranges that have never been requested
453  return std::any_of( _requestedRanges.begin(), _requestedRanges.end(), []( const auto &range ){ return range._rangeState == CurlMultiPartHandler::Pending; });
454  }
455 
457  {
458  bool isRangeContinuation = std::holds_alternative<prepareNextRangeBatch_t>( _runningMode );
459  if ( isRangeContinuation ) {
460  MIL << _easyHandle << " " << "Continuing a previously started range batch." << std::endl;
461  _runningMode = running_t( std::move(std::get<prepareNextRangeBatch_t>( _runningMode )) );
462  } else {
463  _runningMode = running_t( std::move(std::get<pending_t>( _runningMode )) );
464  }
465 
466  auto &m = std::get<running_t>( _runningMode );
467 
468  if ( m._activityTimer ) {
469  DBG_MEDIA << _easyHandle << " Setting activity timeout to: " << _settings.timeout() << std::endl;
470  m._activityTimer->connect( &Timer::sigExpired, *this, &NetworkRequestPrivate::onActivityTimeout );
471  m._activityTimer->start( static_cast<uint64_t>( _settings.timeout() * 1000 ) );
472  }
473 
474  if ( !isRangeContinuation )
475  _sigStarted.emit( *z_func() );
476  }
477 
479  {
480  if ( std::holds_alternative<running_t>(_runningMode) ) {
481  auto &rmode = std::get<running_t>( _runningMode );
482  if ( rmode._partialHelper )
483  rmode._partialHelper->finalize();
484  }
485  }
486 
488  {
489  finished_t resState;
490  resState._result = std::move(err);
491 
492  if ( std::holds_alternative<running_t>(_runningMode) ) {
493 
494  auto &rmode = std::get<running_t>( _runningMode );
495  resState._downloaded = rmode._downloaded;
496  resState._contentLenght = rmode._contentLenght;
497 
499  if ( _requestedRanges.size( ) ) {
500  //we have a successful download lets see if we got everything we needed
501  if ( !rmode._partialHelper->verifyData() ){
502  NetworkRequestError::Type err = rmode._partialHelper->lastError();
503  resState._result = NetworkRequestErrorPrivate::customError( err, std::string(rmode._partialHelper->lastErrorMessage()) );
504  }
505 
506  // if we have ranges we need to fill our digest from the full file
508  if ( fseek( rmode._outFile, 0, SEEK_SET ) != 0 ) {
509  resState._result = NetworkRequestErrorPrivate::customError( NetworkRequestError::InternalError, "Unable to set output file pointer." );
510  } else {
511  constexpr size_t bufSize = 4096;
512  char buf[bufSize];
513  while( auto cnt = fread(buf, 1, bufSize, rmode._outFile ) > 0 ) {
514  _fileVerification->_fileDigest.update(buf, cnt);
515  }
516  }
517  }
518  } // if ( _requestedRanges.size( ) )
519  }
520 
521  // finally check the file digest if we have one
523  const UByteArray &calcSum = _fileVerification->_fileDigest.digestVector ();
524  const UByteArray &expSum = zypp::Digest::hexStringToUByteArray( _fileVerification->_fileChecksum.checksum () );
525  if ( calcSum != expSum ) {
528  , (zypp::str::Format("Invalid file checksum %1%, expected checksum %2%")
529  % _fileVerification->_fileDigest.digest()
530  % _fileVerification->_fileChecksum.checksum () ) );
531  }
532  }
533 
534  rmode._outFile.reset();
535  }
536 
537  _runningMode = std::move( resState );
538  _sigFinished.emit( *z_func(), std::get<finished_t>(_runningMode)._result );
539  }
540 
542  {
544  _headers.reset( nullptr );
545  _errorBuf.fill( 0 );
547 
548  if ( _fileVerification )
549  _fileVerification->_fileDigest.reset ();
550 
551  std::for_each( _requestedRanges.begin (), _requestedRanges.end(), []( CurlMultiPartHandler::Range &range ) {
552  range.restart();
553  });
554  }
555 
557  {
558  MIL_MEDIA << _easyHandle << " Request timeout interval: " << t.interval()<< " remaining: " << t.remaining() << std::endl;
559  std::map<std::string, boost::any> extraInfo;
560  extraInfo.insert( {"requestUrl", _url } );
561  extraInfo.insert( {"filepath", _targetFile } );
562  _dispatcher->cancel( *z_func(), NetworkRequestErrorPrivate::customError( NetworkRequestError::Timeout, "Download timed out", std::move(extraInfo) ) );
563  }
564 
566  {
567  return std::string( _errorBuf.data() );
568  }
569 
571  {
572  if ( std::holds_alternative<running_t>( _runningMode ) ){
573  auto &rmode = std::get<running_t>( _runningMode );
574  if ( rmode._activityTimer && rmode._activityTimer->isRunning() )
575  rmode._activityTimer->start();
576  }
577  }
578 
579  int NetworkRequestPrivate::curlProgressCallback( void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow )
580  {
581  if ( !clientp )
582  return CURLE_OK;
583  NetworkRequestPrivate *that = reinterpret_cast<NetworkRequestPrivate *>( clientp );
584 
585  if ( !std::holds_alternative<running_t>(that->_runningMode) ){
586  DBG << that->_easyHandle << " " << "Curl progress callback was called in invalid state "<< that->z_func()->state() << std::endl;
587  return -1;
588  }
589 
590  auto &rmode = std::get<running_t>( that->_runningMode );
591 
592  //reset the timer
593  that->resetActivityTimer();
594 
595  rmode._isInCallback = true;
596  if ( rmode._lastProgressNow != dlnow ) {
597  rmode._lastProgressNow = dlnow;
598  that->_sigProgress.emit( *that->z_func(), dltotal, dlnow, ultotal, ulnow );
599  }
600  rmode._isInCallback = false;
601 
602  return rmode._cachedResult ? CURLE_ABORTED_BY_CALLBACK : CURLE_OK;
603  }
604 
605  size_t NetworkRequestPrivate::headerfunction( char *ptr, size_t bytes )
606  {
607  //it is valid to call this function with no data to write, just return OK
608  if ( bytes == 0)
609  return 0;
610 
612 
614 
615  std::string_view hdr( ptr, bytes );
616 
617  hdr.remove_prefix( std::min( hdr.find_first_not_of(" \t\r\n"), hdr.size() ) );
618  const auto lastNonWhitespace = hdr.find_last_not_of(" \t\r\n");
619  if ( lastNonWhitespace != hdr.npos )
620  hdr.remove_suffix( hdr.size() - (lastNonWhitespace + 1) );
621  else
622  hdr = std::string_view();
623 
624  auto &rmode = std::get<running_t>( _runningMode );
625  if ( !hdr.size() ) {
626  return ( bytes );
627  }
628  if ( _expectedFileSize && rmode._partialHelper ) {
629  const auto &repSize = rmode._partialHelper->reportedFileSize ();
630  if ( repSize && repSize != _expectedFileSize ) {
631  rmode._cachedResult = NetworkRequestErrorPrivate::customError( NetworkRequestError::InternalError, "Reported downloaded data length is not what was expected." );
632  return 0;
633  }
634  }
635  if ( zypp::strv::hasPrefixCI( hdr, "HTTP/" ) ) {
636 
637  long statuscode = 0;
638  (void)curl_easy_getinfo( _easyHandle, CURLINFO_RESPONSE_CODE, &statuscode);
639 
640  // if we have a status 204 we need to create a empty file
641  if( statuscode == 204 && !( _options & NetworkRequest::ConnectionTest ) && !( _options & NetworkRequest::HeadRequest ) )
643 
644  } else if ( zypp::strv::hasPrefixCI( hdr, "Location:" ) ) {
645  _lastRedirect = hdr.substr( 9 );
646  DBG << _easyHandle << " " << "redirecting to " << _lastRedirect << std::endl;
647 
648  } else if ( zypp::strv::hasPrefixCI( hdr, "Content-Length:") ) {
649  auto lenStr = str::trim( hdr.substr( 15 ), zypp::str::TRIM );
650  auto str = std::string ( lenStr.data(), lenStr.length() );
651  auto len = zypp::str::strtonum<typename zypp::ByteCount::SizeType>( str.data() );
652  if ( len > 0 ) {
653  DBG << _easyHandle << " " << "Got Content-Length Header: " << len << std::endl;
654  rmode._contentLenght = zypp::ByteCount(len, zypp::ByteCount::B);
655  }
656  }
657  }
658 
659  return bytes;
660  }
661 
662  size_t NetworkRequestPrivate::writefunction( char *data, std::optional<off_t> offset, size_t max )
663  {
665 
666  //it is valid to call this function with no data to write, just return OK
667  if ( max == 0)
668  return 0;
669 
670  //in case of a HEAD request, we do not write anything
672  return ( max );
673  }
674 
675  auto &rmode = std::get<running_t>( _runningMode );
676 
677  // if we have no open file create or open it
678  if ( !assertOutputFile() )
679  return 0;
680 
681  if ( offset ) {
682  // seek to the given offset
683  if ( fseek( rmode._outFile, *offset, SEEK_SET ) != 0 ) {
685  "Unable to set output file pointer." );
686  return 0;
687  }
688  rmode._currentFileOffset = *offset;
689  }
690 
691  if ( _expectedFileSize && rmode._partialHelper ) {
692  const auto &repSize = rmode._partialHelper->reportedFileSize ();
693  if ( repSize && repSize != _expectedFileSize ) {
694  rmode._cachedResult = NetworkRequestErrorPrivate::customError( NetworkRequestError::InternalError, "Reported downloaded data length is not what was expected." );
695  return 0;
696  }
697  }
698 
699  //make sure we do not write after the expected file size
700  if ( _expectedFileSize && _expectedFileSize <= static_cast<zypp::ByteCount::SizeType>( rmode._currentFileOffset + max) ) {
701  rmode._cachedResult = NetworkRequestErrorPrivate::customError( NetworkRequestError::InternalError, "Downloaded data exceeds expected length." );
702  return 0;
703  }
704 
705  auto written = fwrite( data, 1, max, rmode._outFile );
706  if ( written == 0 )
707  return 0;
708 
709  // if we are not downloading in ranges, we can update the file digest on the fly if we have one
710  if ( !rmode._partialHelper && _fileVerification ) {
711  _fileVerification->_fileDigest.update( data, written );
712  }
713 
714  rmode._currentFileOffset += written;
715 
716  // count the number of real bytes we have downloaded so far
717  rmode._downloaded += written;
718  _sigBytesDownloaded.emit( *z_func(), rmode._downloaded );
719 
720  return written;
721  }
722 
724  {
725  auto rmode = std::get_if<NetworkRequestPrivate::running_t>( &_runningMode );
726  if ( !rmode || !rmode->_partialHelper || !rmode->_partialHelper->hasError() )
727  return;
728 
729  // oldest cached result wins
730  if ( rmode->_cachedResult )
731  return;
732 
733  auto lastErr = NetworkRequestErrorPrivate::customError( rmode->_partialHelper->lastError() , std::string(rmode->_partialHelper->lastErrorMessage()) );
734  MIL_MEDIA << _easyHandle << " Multipart handler announced error code " << lastErr.toString () << std::endl;
735  rmode->_cachedResult = lastErr;
736  }
737 
739 
741  : Base ( *new NetworkRequestPrivate( std::move(url), std::move(targetFile), std::move(fMode), *this ) )
742  {
743  }
744 
746  {
747  Z_D();
748 
749  if ( d->_dispatcher )
750  d->_dispatcher->cancel( *this, "Request destroyed while still running" );
751  }
752 
754  {
755  d_func()->_expectedFileSize = std::move( expectedFileSize );
756  }
757 
758  void NetworkRequest::setPriority( NetworkRequest::Priority prio, bool triggerReschedule )
759  {
760  Z_D();
761  d->_priority = prio;
762  if ( state() == Pending && triggerReschedule && d->_dispatcher )
763  d->_dispatcher->reschedule();
764  }
765 
767  {
768  return d_func()->_priority;
769  }
770 
771  void NetworkRequest::setOptions( Options opt )
772  {
773  d_func()->_options = opt;
774  }
775 
776  NetworkRequest::Options NetworkRequest::options() const
777  {
778  return d_func()->_options;
779  }
780 
781  void NetworkRequest::addRequestRange(size_t start, size_t len, std::optional<zypp::Digest> &&digest, CheckSumBytes expectedChkSum , std::any userData, std::optional<size_t> digestCompareLen, std::optional<size_t> chksumpad )
782  {
783  Z_D();
784  if ( state() == Running )
785  return;
786 
787  d->_requestedRanges.push_back( Range::make( start, len, std::move(digest), std::move( expectedChkSum ), std::move( userData ), digestCompareLen, chksumpad ) );
788  }
789 
791  {
792  Z_D();
793  if ( state() == Running )
794  return;
795 
796  d->_requestedRanges.push_back( std::move(range) );
797  auto &rng = d->_requestedRanges.back();
798  rng._rangeState = CurlMultiPartHandler::Pending;
799  rng.bytesWritten = 0;
800  if ( rng._digest )
801  rng._digest->reset();
802  }
803 
805  {
806  Z_D();
807  if ( state() == Running )
808  return false;
809 
810  zypp::Digest fDig;
811  if ( !fDig.create( expected.type () ) )
812  return false;
813 
814  d->_fileVerification = NetworkRequestPrivate::FileVerifyInfo{
815  ._fileDigest = std::move(fDig),
816  ._fileChecksum = expected
817  };
818  return true;
819  }
820 
822  {
823  Z_D();
824  if ( state() == Running )
825  return;
826  d->_requestedRanges.clear();
827  }
828 
829  std::vector<NetworkRequest::Range> NetworkRequest::failedRanges() const
830  {
831  const auto mystate = state();
832  if ( mystate != Finished && mystate != Error )
833  return {};
834 
835  Z_D();
836 
837  std::vector<Range> failed;
838  for ( auto &r : d->_requestedRanges ) {
839  if ( r._rangeState != CurlMultiPartHandler::Finished ) {
840  failed.push_back( r.clone() );
841  }
842  }
843  return failed;
844  }
845 
846  const std::vector<NetworkRequest::Range> &NetworkRequest::requestedRanges() const
847  {
848  return d_func()->_requestedRanges;
849  }
850 
851  const std::string &NetworkRequest::lastRedirectInfo() const
852  {
853  return d_func()->_lastRedirect;
854  }
855 
857  {
858  return d_func()->_easyHandle;
859  }
860 
861  std::optional<zyppng::NetworkRequest::Timings> NetworkRequest::timings() const
862  {
863  const auto myerr = error();
864  const auto mystate = state();
865  if ( mystate != Finished )
866  return {};
867 
868  Timings t;
869 
870  auto getMeasurement = [ this ]( const CURLINFO info, std::chrono::microseconds &target ){
871  using FPSeconds = std::chrono::duration<double, std::chrono::seconds::period>;
872  double val = 0;
873  const auto res = curl_easy_getinfo( d_func()->_easyHandle, info, &val );
874  if ( CURLE_OK == res ) {
875  target = std::chrono::duration_cast<std::chrono::microseconds>( FPSeconds(val) );
876  }
877  };
878 
879  getMeasurement( CURLINFO_NAMELOOKUP_TIME, t.namelookup );
880  getMeasurement( CURLINFO_CONNECT_TIME, t.connect);
881  getMeasurement( CURLINFO_APPCONNECT_TIME, t.appconnect);
882  getMeasurement( CURLINFO_PRETRANSFER_TIME , t.pretransfer);
883  getMeasurement( CURLINFO_TOTAL_TIME, t.total);
884  getMeasurement( CURLINFO_REDIRECT_TIME, t.redirect);
885 
886  return t;
887  }
888 
889  std::vector<char> NetworkRequest::peekData( off_t offset, size_t count ) const
890  {
891  Z_D();
892 
893  if ( !std::holds_alternative<NetworkRequestPrivate::running_t>( d->_runningMode) )
894  return {};
895 
896  const auto &rmode = std::get<NetworkRequestPrivate::running_t>( d->_runningMode );
897  return zypp::io::peek_data_fd( rmode._outFile, offset, count );
898  }
899 
901  {
902  return d_func()->_url;
903  }
904 
905  void NetworkRequest::setUrl(const Url &url)
906  {
907  Z_D();
908  if ( state() == NetworkRequest::Running )
909  return;
910 
911  d->_url = url;
912  }
913 
915  {
916  return d_func()->_targetFile;
917  }
918 
920  {
921  Z_D();
922  if ( state() == NetworkRequest::Running )
923  return;
924  d->_targetFile = path;
925  }
926 
928  {
929  return d_func()->_fMode;
930  }
931 
933  {
934  Z_D();
935  if ( state() == NetworkRequest::Running )
936  return;
937  d->_fMode = std::move( mode );
938  }
939 
940  std::string NetworkRequest::contentType() const
941  {
942  char *ptr = NULL;
943  if ( curl_easy_getinfo( d_func()->_easyHandle, CURLINFO_CONTENT_TYPE, &ptr ) == CURLE_OK && ptr )
944  return std::string(ptr);
945  return std::string();
946  }
947 
949  {
950  return std::visit([](auto& arg) -> zypp::ByteCount {
951  using T = std::decay_t<decltype(arg)>;
952  if constexpr (std::is_same_v<T, NetworkRequestPrivate::pending_t> || std::is_same_v<T, NetworkRequestPrivate::prepareNextRangeBatch_t> )
953  return zypp::ByteCount(0);
954  else if constexpr (std::is_same_v<T, NetworkRequestPrivate::running_t>
955  || std::is_same_v<T, NetworkRequestPrivate::finished_t>)
956  return arg._contentLenght;
957  else
958  static_assert(always_false<T>::value, "Unhandled state type");
959  }, d_func()->_runningMode);
960  }
961 
963  {
964  return std::visit([](auto& arg) -> zypp::ByteCount {
965  using T = std::decay_t<decltype(arg)>;
966  if constexpr (std::is_same_v<T, NetworkRequestPrivate::pending_t>)
967  return zypp::ByteCount();
968  else if constexpr (std::is_same_v<T, NetworkRequestPrivate::running_t>
969  || std::is_same_v<T, NetworkRequestPrivate::prepareNextRangeBatch_t>
970  || std::is_same_v<T, NetworkRequestPrivate::finished_t>)
971  return arg._downloaded;
972  else
973  static_assert(always_false<T>::value, "Unhandled state type");
974  }, d_func()->_runningMode);
975  }
976 
978  {
979  return d_func()->_settings;
980  }
981 
983  {
984  return std::visit([this](auto& arg) {
985  using T = std::decay_t<decltype(arg)>;
986  if constexpr (std::is_same_v<T, NetworkRequestPrivate::pending_t>)
987  return Pending;
988  else if constexpr (std::is_same_v<T, NetworkRequestPrivate::running_t> || std::is_same_v<T, NetworkRequestPrivate::prepareNextRangeBatch_t> )
989  return Running;
990  else if constexpr (std::is_same_v<T, NetworkRequestPrivate::finished_t>) {
991  if ( std::get<NetworkRequestPrivate::finished_t>( d_func()->_runningMode )._result.isError() )
992  return Error;
993  else
994  return Finished;
995  }
996  else
997  static_assert(always_false<T>::value, "Unhandled state type");
998  }, d_func()->_runningMode);
999  }
1000 
1002  {
1003  const auto s = state();
1004  if ( s != Error && s != Finished )
1005  return NetworkRequestError();
1006  return std::get<NetworkRequestPrivate::finished_t>( d_func()->_runningMode)._result;
1007  }
1008 
1010  {
1011  if ( !hasError() )
1012  return std::string();
1013 
1014  return error().nativeErrorString();
1015  }
1016 
1018  {
1019  return error().isError();
1020  }
1021 
1022  bool NetworkRequest::addRequestHeader( const std::string &header )
1023  {
1024  Z_D();
1025 
1026  curl_slist *res = curl_slist_append( d->_headers ? d->_headers.get() : nullptr, header.c_str() );
1027  if ( !res )
1028  return false;
1029 
1030  if ( !d->_headers )
1031  d->_headers = std::unique_ptr< curl_slist, decltype (&curl_slist_free_all) >( res, &curl_slist_free_all );
1032 
1033  return true;
1034  }
1035 
1037  {
1038  return d_func()->_sigStarted;
1039  }
1040 
1042  {
1043  return d_func()->_sigBytesDownloaded;
1044  }
1045 
1047  {
1048  return d_func()->_sigProgress;
1049  }
1050 
1052  {
1053  return d_func()->_sigFinished;
1054  }
1055 
1056 }
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:551
Signal< void(NetworkRequest &req)> _sigStarted
Definition: request_p.h:129
long timeout() const
transfer timeout
const Pathname & certificateAuthoritiesPath() const
SSL certificate authorities path ( default: /etc/ssl/certs )
std::string errorMessage() const
Definition: request.cc:565
bool isError() const
isError Will return true if this is a actual error
T trim(StrType &&s, const Trim trim_r)
Definition: string.h:35
#define MIL
Definition: Logger.h:100
void setCurlOption(CURLoption opt, T data)
Definition: request_p.h:98
std::string curlUnEscape(const std::string &text_r)
Definition: curlhelper.cc:366
std::optional< Timings > timings() const
After the request is finished query the timings that were collected during download.
Definition: request.cc:861
void * nativeHandle() const
Definition: request.cc:856
#define DBG_MEDIA
Definition: mediadebug_p.h:28
zypp::ByteCount reportedByteCount() const
Returns the number of bytes that are reported from the backend as the full download size...
Definition: request.cc:948
const std::vector< Range > & requestedRanges() const
Definition: request.cc:846
const Pathname & clientCertificatePath() const
SSL client certificate file.
std::chrono::microseconds connect
Definition: request.h:80
std::array< char, CURL_ERROR_SIZE+1 > _errorBuf
Definition: request_p.h:95
void addHeader(std::string &&val_r)
add a header, on the form "Foo: Bar" (trims)
uint64_t interval() const
Definition: timer.cc:94
std::optional< FileVerifyInfo > _fileVerification
The digest for the full file.
Definition: request_p.h:117
The CurlMultiPartHandler class.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:424
void addRequestRange(size_t start, size_t len=0, std::optional< zypp::Digest > &&digest={}, CheckSumBytes expectedChkSum=CheckSumBytes(), std::any userData=std::any(), std::optional< size_t > digestCompareLen={}, std::optional< size_t > chksumpad={})
Definition: request.cc:781
std::string proxyUserPassword() const
returns the proxy user and password as a user:pass string
SignalProxy< void(NetworkRequest &req, zypp::ByteCount count)> sigBytesDownloaded()
Signals that new data has been downloaded, this is only the payload and does not include control data...
Definition: request.cc:1041
int assert_file_mode(const Pathname &path, unsigned mode)
Like assert_file but enforce mode even if the file already exists.
Definition: PathInfo.cc:1210
bool hasPrefixCI(const C_Str &str_r, const C_Str &prefix_r)
Definition: String.h:1030
Compute Message Digests (MD5, SHA1 etc)
Definition: Digest.h:37
NetworkRequest::FileMode _fMode
Definition: request_p.h:119
Store and operate with byte count.
Definition: ByteCount.h:31
const std::string & lastRedirectInfo() const
Definition: request.cc:851
long maxDownloadSpeed() const
Maximum download speed (bytes per second)
const std::string _currentCookieFile
Definition: request_p.h:123
static Range make(size_t start, size_t len=0, std::optional< zypp::Digest > &&digest={}, CheckSumBytes &&expectedChkSum=CheckSumBytes(), std::any &&userData=std::any(), std::optional< size_t > digestCompareLen={}, std::optional< size_t > _dataBlockPadding={})
std::chrono::microseconds pretransfer
Definition: request.h:82
Holds transfer setting.
zypp::ByteCount downloadedByteCount() const
Returns the number of already downloaded bytes as reported by the backend.
Definition: request.cc:962
const std::string & authType() const
get the allowed authentication types
NetworkRequest::Options _options
Definition: request_p.h:109
bool verifyHostEnabled() const
Whether to verify host for ssl.
const std::string & proxyUsername() const
proxy auth username
const char * c_str() const
String representation.
Definition: Pathname.h:112
String related utilities and Regular expression matching.
Definition: Arch.h:363
std::chrono::microseconds appconnect
Definition: request.h:81
constexpr bool always_false
Definition: PathInfo.cc:549
running_t(pending_t &&prevState)
Definition: request.cc:63
std::string nativeErrorString() const
Signal< void(NetworkRequest &req, zypp::ByteCount count)> _sigBytesDownloaded
Definition: request_p.h:130
Convenient building of std::string with boost::format.
Definition: String.h:252
Structure holding values of curlrc options.
Definition: curlconfig.h:26
void setOptions(Options opt)
Definition: request.cc:771
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:37
~NetworkRequestPrivate() override
Definition: request.cc:81
TransferSettings & transferSettings()
Definition: request.cc:977
enum zyppng::NetworkRequestPrivate::ProtocolMode _protocolMode
void setExpectedFileSize(zypp::ByteCount expectedFileSize)
Definition: request.cc:753
void setFileOpenMode(FileMode mode)
Sets the file open mode to mode.
Definition: request.cc:932
bool hasError() const
Checks if there was a error with the request.
Definition: request.cc:1017
void onActivityTimeout(Timer &)
Definition: request.cc:556
SignalProxy< void(Timer &t)> sigExpired()
This signal is always emitted when the timer expires.
Definition: timer.cc:120
const Headers & headers() const
returns a list of all added headers (trimmed)
#define Z_D()
Definition: zyppglobal.h:105
int ZYPP_MEDIA_CURL_IPRESOLVE()
4/6 to force IPv4/v6
Definition: curlhelper.cc:45
zypp::Pathname _targetFile
Definition: request_p.h:107
bool verifyPeerEnabled() const
Whether to verify peer for ssl.
bool empty() const
Test for an empty path.
Definition: Pathname.h:116
void setUrl(const Url &url)
This will change the URL of the request.
Definition: request.cc:905
std::chrono::microseconds namelookup
Definition: request.h:79
static int parseConfig(CurlConfig &config, const std::string &filename="")
Parse a curlrc file and store the result in the config structure.
Definition: curlconfig.cc:24
std::string asString() const
Returns a default string representation of the Url object.
Definition: Url.cc:515
std::string getQueryParam(const std::string &param, EEncoding eflag=zypp::url::E_DECODED) const
Return the value for the specified query parameter.
Definition: Url.cc:678
bool addRequestHeader(const std::string &header)
Definition: request.cc:1022
std::string trim(const std::string &s, const Trim trim_r)
Definition: String.cc:224
const std::string & asString() const
String representation.
Definition: Pathname.h:93
Signal< void(NetworkRequest &req, off_t dltotal, off_t dlnow, off_t ultotal, off_t ulnow)> _sigProgress
Definition: request_p.h:131
std::string asString() const
Error message provided by dumpOn as string.
Definition: Exception.cc:111
long connectTimeout() const
connection timeout
void notifyErrorCodeChanged() override
Definition: request.cc:723
bool initialize(std::string &errBuf)
Definition: request.cc:91
The NetworkRequestError class Represents a error that occured in.
The Timer class provides repetitive and single-shot timers.
Definition: timer.h:44
std::vector< char > peekData(off_t offset, size_t count) const
Definition: request.cc:889
NetworkRequestError error() const
Returns the last set Error.
Definition: request.cc:1001
zypp::ByteCount _expectedFileSize
Definition: request_p.h:110
std::string extendedErrorString() const
In some cases, curl can provide extended error information collected at runtime.
Definition: request.cc:1009
Priority priority() const
Definition: request.cc:766
std::string proxyuserpwd
Definition: curlconfig.h:49
bool setupHandle(std::string &errBuf)
Definition: request.cc:103
const Pathname & clientKeyPath() const
SSL client key file.
std::vector< char > peek_data_fd(FILE *fd, off_t offset, size_t count)
Definition: IOTools.cc:171
bool create(const std::string &name)
initialize creation of a new message digest
Definition: Digest.cc:197
const zypp::Pathname & targetFilePath() const
Returns the target filename path.
Definition: request.cc:914
size_t writefunction(char *ptr, std::optional< off_t > offset, size_t bytes) override
Definition: request.cc:662
std::unique_ptr< curl_slist, decltype(&curl_slist_free_all) > _headers
Definition: request_p.h:140
uint64_t remaining() const
Definition: timer.cc:99
long minDownloadSpeed() const
Minimum download speed (bytes per second) until the connection is dropped.
#define MIL_MEDIA
Definition: mediadebug_p.h:29
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition: Exception.h:440
bool proxyEnabled() const
proxy is enabled
void setTargetFilePath(const zypp::Pathname &path)
Changes the target file path of the download.
Definition: request.cc:919
static int curlProgressCallback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
Definition: request.cc:579
std::string contentType() const
Returns the content type as reported from the server.
Definition: request.cc:940
std::string strerr_cxx(const int err=-1)
static const Unit B
1 Byte
Definition: ByteCount.h:43
bool setExpectedFileChecksum(const zypp::CheckSum &expected)
Definition: request.cc:804
Base class for Exception.
Definition: Exception.h:146
std::string _lastRedirect
to log/report redirections
Definition: request_p.h:122
std::chrono::microseconds total
Definition: request.h:83
bool any_of(const Container &c, Fnc &&cb)
Definition: Algorithm.h:76
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
Definition: Url.cc:606
void setupZYPP_MEDIA_CURL_DEBUG(CURL *curl)
Setup CURLOPT_VERBOSE and CURLOPT_DEBUGFUNCTION according to env::ZYPP_MEDIA_CURL_DEBUG.
Definition: curlhelper.cc:130
void setPriority(Priority prio, bool triggerReschedule=true)
Definition: request.cc:758
State state() const
Returns the current state the HttpDownloadRequest is in.
Definition: request.cc:982
TransferSettings _settings
Definition: request_p.h:108
NetworkRequestDispatcher * _dispatcher
Definition: request_p.h:126
bool strToBool(const C_Str &str, bool default_r)
Parse str into a bool depending on the default value.
Definition: String.h:429
ZYPP_IMPL_PRIVATE(UnixSignalSource)
static long auth_type_str2long(std::string &auth_type_str)
Converts a string of comma separated list of authetication type names into a long of ORed CURLAUTH_* ...
Definition: curlauthdata.cc:50
void setUserAgentString(std::string &&val_r)
sets the user agent ie: "Mozilla v3" (trims)
Options options() const
Definition: request.cc:776
std::vector< NetworkRequest::Range > _requestedRanges
the requested ranges that need to be downloaded
Definition: request_p.h:111
std::chrono::microseconds redirect
Definition: request.h:84
SignalProxy< void(NetworkRequest &req, const NetworkRequestError &err)> sigFinished()
Signals that the download finished.
Definition: request.cc:1051
typename decay< T >::type decay_t
Definition: TypeTraits.h:42
Signal< void(NetworkRequest &req, const NetworkRequestError &err)> _sigFinished
Definition: request_p.h:132
size_t headerfunction(char *ptr, size_t bytes) override
Definition: request.cc:605
Type type() const
type Returns the type of the error
SignalProxy< void(NetworkRequest &req)> sigStarted()
Signals that the dispatcher dequeued the request and actually starts downloading data.
Definition: request.cc:1036
std::string userPassword() const
returns the user and password as a user:pass string
#define EXPLICITLY_NO_PROXY
Definition: curlhelper_p.h:23
FileMode fileOpenMode() const
Returns the currently configured file open mode.
Definition: request.cc:927
std::vector< Range > failedRanges() const
Definition: request.cc:829
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
NetworkRequestPrivate(Url &&url, zypp::Pathname &&targetFile, NetworkRequest::FileMode fMode, NetworkRequest &p)
Definition: request.cc:73
CURLcode setCurlRedirProtocols(CURL *curl)
Definition: curlhelper.cc:515
void setResult(NetworkRequestError &&err)
Definition: request.cc:487
const std::string & proxy() const
proxy host
static zyppng::NetworkRequestError customError(NetworkRequestError::Type t, std::string &&errorMsg="", std::map< std::string, boost::any > &&extraInfo={})
SignalProxy< void(NetworkRequest &req, off_t dltotal, off_t dlnow, off_t ultotal, off_t ulnow)> sigProgress()
Signals if there was data read from the download.
Definition: request.cc:1046
bool prepareToContinue(std::string &errBuf)
Definition: request.cc:411
~NetworkRequest() override
Definition: request.cc:745
const std::string & userAgentString() const
user agent string (trimmed)
Url manipulation class.
Definition: Url.h:92
bool headRequestsAllowed() const
whether HEAD requests are allowed
#define DBG
Definition: Logger.h:99
ZYppCommitResult & _result
Definition: TargetImpl.cc:1610
std::variant< pending_t, running_t, prepareNextRangeBatch_t, finished_t > _runningMode
Definition: request_p.h:188