libzypp: zyppng::NetworkRequest Class Reference

libzypp 17.38.11

zyppng::NetworkRequest Class Reference

`#include <zypp-curl/ng/network/request.h>`

Inheritance diagram for zyppng::NetworkRequest:

## Classes
struct | Timings

## Public Types
enum | State { Pending , Running , Finished , Error }
enum | Priority { Normal , High , Critical = 100 }
enum | FileMode { WriteExclusive , WriteShared }
enum | OptionBits { Default = 0x00 , HeadRequest = 0x01 , ConnectionTest = 0x02 }
using | Ptr = std::shared_ptr<NetworkRequest>
using | WeakPtr = std::weak_ptr<NetworkRequest>
using | DigestPtr = std::shared_ptr<zypp::Digest>
using | CheckSumBytes = UByteArray
using | Range = CurlMultiPartHandler::Range
Public Types inherited from zyppng::Base
using | Ptr = std::shared_ptr<Base>
using | WeakPtr = std::weak_ptr<Base>

## Public Member Functions
| ZYPP_DECLARE_FLAGS (Options, OptionBits)
| NetworkRequest (Url url, zypp::Pathname targetFile, FileMode fMode=WriteExclusive)
| ~NetworkRequest () override
void | setExpectedFileSize (zypp::ByteCount expectedFileSize)
zypp::ByteCount | expectedFileSize () const
void | setPriority (Priority prio, bool triggerReschedule=true)
Priority | priority () const
void | setOptions (Options opt)
Options | options () const
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={})
void | addRequestRange (Range &&range)
bool | setExpectedFileChecksum (const zypp::CheckSum &expected)
void | resetRequestRanges ()
std::vector< Range > | failedRanges () const
const std::vector< Range > & | requestedRanges () const
const std::string & | lastRedirectInfo () const
void * | nativeHandle () const
std::optional< Timings > | timings () const
| After the request is finished query the timings that were collected during download.
std::vector< char > | peekData (off_t offset, size_t count) const
Url | url () const
void | setUrl (const Url &url)
| This will change the URL of the request.
const zypp::Pathname & | targetFilePath () const
| Returns the target filename path.
void | setTargetFilePath (const zypp::Pathname &path)
| Changes the target file path of the download.
FileMode | fileOpenMode () const
| Returns the currently configured file open mode.
void | setFileOpenMode (FileMode mode)
| Sets the file open mode to mode.
std::string | contentType () const
| Returns the content type as reported from the server.
zypp::ByteCount | reportedByteCount () const
| Returns the number of bytes that are reported from the backend as the full download size, those can be 0 even when the download is already running.
zypp::ByteCount | downloadedByteCount () const
| Returns the number of already downloaded bytes as reported by the backend.
TransferSettings & | transferSettings ()
State | state () const
| Returns the current state the HttpDownloadRequest is in.
NetworkRequestError | error () const
| Returns the last set Error.
std::string | extendedErrorString () const
| In some cases, curl can provide extended error information collected at runtime.
bool | hasError () const
| Checks if there was a error with the request.
bool | addRequestHeader (const std::string &header)
const zypp::Pathname & | cookieFile () const
void | setCookieFile (zypp::Pathname cookieFile)
SignalProxy< void(NetworkRequest &req)> | sigStarted ()
| Signals that the dispatcher dequeued the request and actually starts downloading data.
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 bytes.
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.
SignalProxy< void(NetworkRequest &req, const NetworkRequestError &err)> | sigFinished ()
| Signals that the download finished.
Public Member Functions inherited from zyppng::Base
| Base ()
virtual | ~Base ()
WeakPtr | parent () const
void | addChild (const Base::Ptr &child)
void | removeChild (const Ptr &child)
const std::unordered_set< Ptr > & | children () const
std::thread::id | threadId () const
template<typename T>
std::vector< std::weak_ptr< T > > | findChildren () const
template<typename T>
std::shared_ptr< T > | shared_this () const
template<typename T>
std::shared_ptr< T > | shared_this ()
template<typename T>
std::weak_ptr< T > | weak_this () const
template<typename T>
std::weak_ptr< T > | weak_this ()
template<typename SenderFunc, typename ReceiverFunc>
auto | connect (SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc)
template<typename SenderFunc, typename ReceiverFunc, typename ... Tracker>
std::enable_if_t< std::is_member_function_pointer_v< SenderFunc >, connection > | connectFunc (SenderFunc &&sFun, ReceiverFunc &&rFunc, const Tracker &...trackers)
void | setData (uint32_t quark, zypp::AutoDispose< void * > data)
void * | data (uint32_t quark)
void | clearData (uint32_t quark)

## Friends
class | NetworkRequestDispatcher
class | NetworkRequestDispatcherPrivate

## Additional Inherited Members
Static Public Member Functions inherited from zyppng::Base
template<typename Obj, typename Functor>
static decltype(auto) | make_base_slot (Obj *o, Functor &&f)
template<typename SenderFunc, typename ReceiverFunc>
static auto | connect (typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc)
template<typename SenderFunc, typename ReceiverFunc, typename ... Tracker>
static auto | connectFunc (typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, ReceiverFunc &&rFunc, const Tracker &...trackers)
Protected Member Functions inherited from zyppng::Base
| Base (BasePrivate &dd)
Protected Attributes inherited from zyppng::Base
std::unique_ptr< BasePrivate > | d_ptr

## Detailed Description

Represents a (http/https/ftp) request. This is the low level API for the

See also
  zyppng::Downloader , usually it makes more sense to use the Downloader for the more features it supports. After creating a NetworkRequest and changing the required settings is enqueued to the
  zyppng::NetworkRequestDispatcher.

Definition at line 42 of file request.h.

## Member Typedef Documentation

## ◆ Ptr

using zyppng::NetworkRequest::Ptr = std::shared_ptr<NetworkRequest>

Definition at line 46 of file request.h.

## ◆ WeakPtr

using zyppng::NetworkRequest::WeakPtr = std::weak_ptr<NetworkRequest>

Definition at line 47 of file request.h.

## ◆ DigestPtr

using zyppng::NetworkRequest::DigestPtr = std::shared_ptr<zypp::Digest>

Definition at line 48 of file request.h.

## ◆ CheckSumBytes

using zyppng::NetworkRequest::CheckSumBytes = UByteArray

Definition at line 49 of file request.h.

## ◆ Range

using zyppng::NetworkRequest::Range = CurlMultiPartHandler::Range

Definition at line 76 of file request.h.

## Member Enumeration Documentation

## ◆ State

enum zyppng::NetworkRequest::State

Enumerator
Pending |
Running |
Finished |
Error |

Definition at line 51 of file request.h.

## ◆ Priority

enum zyppng::NetworkRequest::Priority

Enumerator
Normal |
High |
Critical |

Definition at line 58 of file request.h.

## ◆ FileMode

enum zyppng::NetworkRequest::FileMode

Enumerator
WriteExclusive |
WriteShared |

Definition at line 64 of file request.h.

## ◆ OptionBits

enum zyppng::NetworkRequest::OptionBits

Enumerator
Default |
HeadRequest |
ConnectionTest |

Definition at line 69 of file request.h.

## Constructor & Destructor Documentation

## ◆ NetworkRequest()

zyppng::NetworkRequest::NetworkRequest | ( | zyppng::Url | url,
|  | zypp::Pathname | targetFile,
|  | FileMode | fMode = WriteExclusive )

Parameters

  url | The source URL of the download
  targetFile | The path where the file should be stored
  fMode | The mode in which the file is opened in.

Definition at line 753 of file request.cc.

## ◆ ~NetworkRequest()

zyppng::NetworkRequest::~NetworkRequest | ( |  | ) |
| override

Definition at line 758 of file request.cc.

## Member Function Documentation

## ◆ ZYPP_DECLARE_FLAGS()

zyppng::NetworkRequest::ZYPP_DECLARE_FLAGS | ( | Options | ,
|  | OptionBits | )

## ◆ setExpectedFileSize()

void zyppng::NetworkRequest::setExpectedFileSize | ( | zypp::ByteCount | expectedFileSize | ) |

Sets the expected file size for the download. In case of a Multi-Range-Download the NetworkRequest will check if the download would write behind the expectedFileSize and fail.

Definition at line 766 of file request.cc.

## ◆ expectedFileSize()

zypp::ByteCount zyppng::NetworkRequest::expectedFileSize | ( |  | ) | const

Definition at line 771 of file request.cc.

## ◆ setPriority()

void zyppng::NetworkRequest::setPriority | ( | NetworkRequest::Priority | prio,
|  | bool | triggerReschedule = true )

Sets the priority of the NetworkRequest, this will affect where the

See also
  NetworkRequestDispatcher puts the Request in the Queue.

Note
  changing this makes only sense in Pending state.

Definition at line 776 of file request.cc.

## ◆ priority()

NetworkRequest::Priority zyppng::NetworkRequest::priority | ( |  | ) | const

Returns the requested priority of the NetworkRequest

Definition at line 784 of file request.cc.

## ◆ setOptions()

void zyppng::NetworkRequest::setOptions | ( | Options | opt | ) |

Change request options.

Note
  changing this makes only sense before the request was started

Definition at line 789 of file request.cc.

## ◆ options()

NetworkRequest::Options zyppng::NetworkRequest::options | ( |  | ) | const

Returns the currently set options

Definition at line 794 of file request.cc.

## ◆ addRequestRange() [1/2]

void zyppng::NetworkRequest::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 = {} )

Adds a new range to the requested range list, the ranges can not overlap

Note
  This will not change a running download

Definition at line 799 of file request.cc.

## ◆ addRequestRange() [2/2]

void zyppng::NetworkRequest::addRequestRange | ( | Range && | range | ) |

Definition at line 808 of file request.cc.

## ◆ setExpectedFileChecksum()

bool zyppng::NetworkRequest::setExpectedFileChecksum | ( | const zypp::CheckSum & | expected | ) |

Sets the expected checksum for the full file.

Note
  This will not change a running download

Definition at line 822 of file request.cc.

## ◆ resetRequestRanges()

void zyppng::NetworkRequest::resetRequestRanges | ( |  | ) |

Clears all requested ranges, the next download will get the complete file

Note
  This will not change a running download

Definition at line 839 of file request.cc.

## ◆ failedRanges()

std::vector< NetworkRequest::Range > zyppng::NetworkRequest::failedRanges | ( |  | ) | const

Definition at line 847 of file request.cc.

## ◆ requestedRanges()

const std::vector< NetworkRequest::Range > & zyppng::NetworkRequest::requestedRanges | ( |  | ) | const

Definition at line 864 of file request.cc.

## ◆ lastRedirectInfo()

const std::string & zyppng::NetworkRequest::lastRedirectInfo | ( |  | ) | const

Returns the last redirect information from the headers.

Definition at line 869 of file request.cc.

## ◆ nativeHandle()

void * zyppng::NetworkRequest::nativeHandle | ( |  | ) | const

Returns a pointer to the native CURL easy handle

Note
  consider adding the functionality here instead of using the Handle directly. In case we ever decide to switch out the CURL backend your code will break

Definition at line 874 of file request.cc.

## ◆ timings()

std::optional< zyppng::NetworkRequest::Timings > zyppng::NetworkRequest::timings | ( |  | ) | const

After the request is finished query the timings that were collected during download.

Definition at line 879 of file request.cc.

## ◆ peekData()

std::vector< char > zyppng::NetworkRequest::peekData | ( | off_t | offset,
|  | size_t | count ) const

Will return the data at offset with length count. If there is not yet enough data a empty vector will be returned

Definition at line 907 of file request.cc.

## ◆ url()

Url zyppng::NetworkRequest::url | ( |  | ) | const

Returns the request URL

Definition at line 918 of file request.cc.

## ◆ setUrl()

void zyppng::NetworkRequest::setUrl | ( | const Url & | url | ) |

This will change the URL of the request.

Note
  calling this on a currently running request has no impact

Definition at line 923 of file request.cc.

## ◆ targetFilePath()

const zypp::filesystem::Pathname & zyppng::NetworkRequest::targetFilePath | ( |  | ) | const

Returns the target filename path.

Definition at line 932 of file request.cc.

## ◆ setTargetFilePath()

void zyppng::NetworkRequest::setTargetFilePath | ( | const zypp::Pathname & | path | ) |

Changes the target file path of the download.

Note
  calling this on a currently running request has no impact

Definition at line 937 of file request.cc.

## ◆ fileOpenMode()

NetworkRequest::FileMode zyppng::NetworkRequest::fileOpenMode | ( |  | ) | const

Returns the currently configured file open mode.

Definition at line 945 of file request.cc.

## ◆ setFileOpenMode()

void zyppng::NetworkRequest::setFileOpenMode | ( | FileMode | mode | ) |

Sets the file open mode to mode.

Note
  calling this on a currently running request has no impact

Definition at line 950 of file request.cc.

## ◆ contentType()

std::string zyppng::NetworkRequest::contentType | ( |  | ) | const

Returns the content type as reported from the server.

Note
  can only return a valid value if the download has started already

Definition at line 958 of file request.cc.

## ◆ reportedByteCount()

zypp::ByteCount zyppng::NetworkRequest::reportedByteCount | ( |  | ) | const

Returns the number of bytes that are reported from the backend as the full download size, those can be 0 even when the download is already running.

Note
  When downloading ranges, the reported byte count could be reported just partially due to range batching.

Definition at line 966 of file request.cc.

## ◆ downloadedByteCount()

zypp::ByteCount zyppng::NetworkRequest::downloadedByteCount | ( |  | ) | const

Returns the number of already downloaded bytes as reported by the backend.

Definition at line 980 of file request.cc.

## ◆ transferSettings()

TransferSettings & zyppng::NetworkRequest::transferSettings | ( |  | ) |

Returns a writeable reference to the internal

See also
  zyppng::TransferSettings.

Note
  calling this on a already running request has no impact

Definition at line 995 of file request.cc.

## ◆ state()

NetworkRequest::State zyppng::NetworkRequest::state | ( |  | ) | const

Returns the current state the HttpDownloadRequest is in.

Definition at line 1000 of file request.cc.

## ◆ error()

NetworkRequestError zyppng::NetworkRequest::error | ( |  | ) | const

Returns the last set Error.

Definition at line 1019 of file request.cc.

## ◆ extendedErrorString()

std::string zyppng::NetworkRequest::extendedErrorString | ( |  | ) | const

In some cases, curl can provide extended error information collected at runtime.

In those cases, it is possible to query that information.

Definition at line 1027 of file request.cc.

## ◆ hasError()

bool zyppng::NetworkRequest::hasError | ( |  | ) | const

Checks if there was a error with the request.

Definition at line 1035 of file request.cc.

## ◆ addRequestHeader()

bool zyppng::NetworkRequest::addRequestHeader | ( | const std::string & | header | ) |

Adds a raw header to the request data. Use this to send custom headers to the server.

Definition at line 1040 of file request.cc.

## ◆ cookieFile()

const zypp::Pathname & zyppng::NetworkRequest::cookieFile | ( |  | ) | const

Return the currently used path for the cookie file

Definition at line 1054 of file request.cc.

## ◆ setCookieFile()

void zyppng::NetworkRequest::setCookieFile | ( | zypp::Pathname | cookieFile | ) |

Set path to use for the cookie file if enabled via TransferSettings.

Note
  calling this on a already running request has no impact

Definition at line 1059 of file request.cc.

## ◆ sigStarted()

SignalProxy< void(NetworkRequest &req)> zyppng::NetworkRequest::sigStarted | ( |  | ) |

Signals that the dispatcher dequeued the request and actually starts downloading data.

Definition at line 1064 of file request.cc.

## ◆ sigBytesDownloaded()

SignalProxy< void(NetworkRequest &req, zypp::ByteCount count)> zyppng::NetworkRequest::sigBytesDownloaded | ( |  | ) |

Signals that new data has been downloaded, this is only the payload and does not include control data bytes.

Definition at line 1069 of file request.cc.

## ◆ sigProgress()

SignalProxy< void(NetworkRequest &req, off_t dltotal, off_t dlnow, off_t ultotal, off_t ulnow)> zyppng::NetworkRequest::sigProgress | ( |  | ) |

Signals if there was data read from the download.

Note
  this signals the raw numbers of bytes that were downloaded, for the number of payload data bytes ( excluding control data ) use downloadedByteCount

Definition at line 1074 of file request.cc.

## ◆ sigFinished()

SignalProxy< void(zyppng::NetworkRequest &req, const zyppng::NetworkRequestError &err)> zyppng::NetworkRequest::sigFinished | ( |  | ) |

Signals that the download finished.

Note
  After this signal was emitted the Curl handle is reset, so all queries to it need to be done in a Slot connected to this signal

Definition at line 1079 of file request.cc.

## Friends And Related Symbol Documentation

## ◆ NetworkRequestDispatcher

friend class NetworkRequestDispatcher
| friend

Definition at line 298 of file request.h.

## ◆ NetworkRequestDispatcherPrivate

friend class NetworkRequestDispatcherPrivate
| friend

Definition at line 299 of file request.h.

The documentation for this class was generated from the following files:

- zypp-curl/ng/network/request.h
- zypp-curl/ng/network/request.cc