libzypp 17.31.23
zyppng::NetworkRequest Class Reference

#include </home/abuild/rpmbuild/BUILD/libzypp-17.31.23/zypp-curl/ng/network/request.h>

Inheritance diagram for zyppng::NetworkRequest:

Classes

struct  Range
 
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
 

Public Member Functions

 ZYPP_DECLARE_FLAGS (Options, OptionBits)
 
 NetworkRequest (Url url, zypp::Pathname targetFile, FileMode fMode=WriteExclusive)
 
virtual ~NetworkRequest ()
 
void setExpectedFileSize (zypp::ByteCount expectedFileSize)
 
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, DigestPtr digest=nullptr, CheckSumBytes expectedChkSum=CheckSumBytes(), std::any userData=std::any(), std::optional< size_t > digestCompareLen={}, std::optional< size_t > chksumpad={})
 
void addRequestRange (const Range &range)
 
void resetRequestRanges ()
 
std::vector< RangefailedRanges () const
 
const std::vector< Range > & requestedRanges () const
 
const std::string & lastRedirectInfo () const
 
void * nativeHandle () const
 
std::optional< Timingstimings () 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::PathnametargetFilePath () 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.
 
TransferSettingstransferSettings ()
 
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)
 
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.
 

Friends

class NetworkRequestDispatcher
 
class NetworkRequestDispatcherPrivate
 

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 40 of file request.h.

Member Typedef Documentation

◆ Ptr

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

Definition at line 44 of file request.h.

◆ WeakPtr

Definition at line 45 of file request.h.

◆ DigestPtr

Definition at line 46 of file request.h.

◆ CheckSumBytes

Definition at line 47 of file request.h.

Member Enumeration Documentation

◆ State

Enumerator
Pending 
Running 
Finished 
Error 

Definition at line 49 of file request.h.

◆ Priority

Enumerator
Normal 
High 
Critical 

Definition at line 56 of file request.h.

◆ FileMode

Enumerator
WriteExclusive 
WriteShared 

Definition at line 62 of file request.h.

◆ OptionBits

Enumerator
Default 
HeadRequest 
ConnectionTest 

Definition at line 67 of file request.h.

Constructor & Destructor Documentation

◆ NetworkRequest()

zyppng::NetworkRequest::NetworkRequest ( Url  url,
zypp::Pathname  targetFile,
FileMode  fMode = WriteExclusive 
)
Parameters
urlThe source URL of the download
targetFileThe path where the file should be stored
fModeThe mode in which the file is opened in.

Definition at line 1109 of file request.cc.

◆ ~NetworkRequest()

zyppng::NetworkRequest::~NetworkRequest ( )
virtual

Definition at line 1114 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 1122 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 1127 of file request.cc.

◆ priority()

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

Returns the requested priority of the NetworkRequest

Definition at line 1135 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 1140 of file request.cc.

◆ options()

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

Returns the currently set options

Definition at line 1145 of file request.cc.

◆ addRequestRange() [1/2]

void zyppng::NetworkRequest::addRequestRange ( size_t  start,
size_t  len = 0,
DigestPtr  digest = nullptr,
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 1150 of file request.cc.

◆ addRequestRange() [2/2]

void zyppng::NetworkRequest::addRequestRange ( const Range range)

Definition at line 1159 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 1173 of file request.cc.

◆ failedRanges()

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

Definition at line 1181 of file request.cc.

◆ requestedRanges()

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

Definition at line 1197 of file request.cc.

◆ lastRedirectInfo()

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

Returns the last redirect information from the headers.

Definition at line 1202 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 1207 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 1212 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 1240 of file request.cc.

◆ url()

Url zyppng::NetworkRequest::url ( ) const

Returns the request URL

Definition at line 1251 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 1256 of file request.cc.

◆ targetFilePath()

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

Returns the target filename path.

Definition at line 1265 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 1270 of file request.cc.

◆ fileOpenMode()

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

Returns the currently configured file open mode.

Definition at line 1278 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 1283 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 1291 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 1299 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 1313 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 1328 of file request.cc.

◆ state()

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

Returns the current state the HttpDownloadRequest is in.

Definition at line 1333 of file request.cc.

◆ error()

NetworkRequestError zyppng::NetworkRequest::error ( ) const

Returns the last set Error.

Definition at line 1352 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 1360 of file request.cc.

◆ hasError()

bool zyppng::NetworkRequest::hasError ( ) const

Checks if there was a error with the request.

Definition at line 1368 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 1373 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 1387 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 1392 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 1397 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 1402 of file request.cc.

Friends And Related Function Documentation

◆ NetworkRequestDispatcher

friend class NetworkRequestDispatcher
friend

Definition at line 297 of file request.h.

◆ NetworkRequestDispatcherPrivate

friend class NetworkRequestDispatcherPrivate
friend

Definition at line 298 of file request.h.


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