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