libzypp  17.22.0
zyppng::NetworkRequest Class Reference

#include <request.h>

Inheritance diagram for zyppng::NetworkRequest:

Public Types

enum  State { Pending, Running, Finished, Error }
 
enum  Priority { Normal, High }
 
enum  FileMode { WriteExclusive, WriteShared }
 
enum  OptionBits { HeadRequest = 0x01 }
 
using Ptr = std::shared_ptr< NetworkRequest >
 
using WeakPtr = std::weak_ptr< NetworkRequest >
 
- 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, off_t start=-1, off_t len=0, FileMode fMode=WriteExclusive)
 
virtual ~NetworkRequest ()
 
void setPriority (Priority prio)
 
Priority priority () const
 
void setOptions (Options opt)
 
Options options () const
 
void setRequestRange (off_t start=-1, off_t len=0)
 
const std::string & lastRedirectInfo () const
 
void * nativeHandle () const
 
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. More...
 
const zypp::PathnametargetFilePath () const
 Returns the target filename path. More...
 
std::string contentType () const
 Returns the content type as reported from the server. More...
 
off_t downloadOffset () const
 Returns the requested start offset. More...
 
off_t 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. More...
 
off_t expectedByteCount () const
 Returns the expected byte count that was passed to the constructor, zero if none was given. More...
 
off_t downloadedByteCount () const
 Returns the number of already downloaded bytes as reported by the backend. More...
 
void setDigest (std::shared_ptr< zypp::Digest > dig)
 Set a. More...
 
std::shared_ptr< zypp::Digestdigest () const
 Returns the currently used. More...
 
void setExpectedChecksum (std::vector< unsigned char > checksum)
 Enables automated checking of downloaded contents against a checksum. More...
 
TransferSettingstransferSettings ()
 
State state () const
 Returns the current state the HttpDownloadRequest is in. More...
 
const NetworkRequestErrorerror () const
 Returns the last set Error. More...
 
std::string extendedErrorString () const
 In some cases curl can provide extended error informations collected at runtime. More...
 
bool hasError () const
 Checks if there was a error with the request. More...
 
bool addRequestHeader (const std::string &header)
 
SignalProxy< void(NetworkRequest &req)> sigStarted ()
 Signals that the dispatcher dequeued the request and actually starts downloading data. More...
 
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. More...
 
SignalProxy< void(NetworkRequest &req, const NetworkRequestError &err)> sigFinished ()
 Signals that the download finished. More...
 
- Public Member Functions inherited from zyppng::Base
 Base ()
 
virtual ~Base ()
 
WeakPtr parent () const
 
void addChild (Base::Ptr child)
 
void removeChild (Ptr child)
 
const std::unordered_set< Ptr > & children () 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 ()
 

Friends

class NetworkRequestDispatcher
 
class NetworkRequestDispatcherPrivate
 

Additional Inherited Members

- Protected Member Functions inherited from zyppng::Base
 Base (BasePrivate &dd)
 
- Protected Attributes inherited from zyppng::Base
std::unique_ptr< BasePrivated_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 35 of file request.h.

Member Typedef Documentation

◆ Ptr

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

Definition at line 39 of file request.h.

◆ WeakPtr

Definition at line 40 of file request.h.

Member Enumeration Documentation

◆ State

Enumerator
Pending 
Running 
Finished 
Error 

Definition at line 42 of file request.h.

◆ Priority

Enumerator
Normal 
High 

Definition at line 49 of file request.h.

◆ FileMode

Enumerator
WriteExclusive 
WriteShared 

Definition at line 54 of file request.h.

◆ OptionBits

Enumerator
HeadRequest 

Definition at line 59 of file request.h.

Constructor & Destructor Documentation

◆ NetworkRequest()

zyppng::NetworkRequest::NetworkRequest ( zyppng::Url  url,
zypp::Pathname  targetFile,
off_t  start = -1,
off_t  len = 0,
FileMode  fMode = WriteExclusive 
)
Parameters
urlThe source URL of the download
targetFileThe path where the file should be stored
startFile offset, if set this will create a range download request
lenFile range length
fModeThe mode in which the file is opened in.

Definition at line 486 of file request.cc.

◆ ~NetworkRequest()

zyppng::NetworkRequest::~NetworkRequest ( )
virtual

Definition at line 491 of file request.cc.

Member Function Documentation

◆ ZYPP_DECLARE_FLAGS()

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

◆ setPriority()

void zyppng::NetworkRequest::setPriority ( NetworkRequest::Priority  prio)

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 before enqueueing the request

Definition at line 502 of file request.cc.

◆ priority()

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

Returns the requested priority of the NetworkRequest

Definition at line 507 of file request.cc.

◆ setOptions()

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

Change request options, currently only the

See also
OptionBits::HeadRequest option is supported
Note
changing this makes only sense before the request was started

Definition at line 512 of file request.cc.

◆ options()

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

Returns the currently set options

Definition at line 517 of file request.cc.

◆ setRequestRange()

void zyppng::NetworkRequest::setRequestRange ( off_t  start = -1,
off_t  len = 0 
)

Sets the range description

Note
This will not change a running download
Parameters
start
len

Definition at line 522 of file request.cc.

◆ lastRedirectInfo()

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

Returns the last redirect information from the headers.

Definition at line 531 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 536 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 541 of file request.cc.

◆ url()

Url zyppng::NetworkRequest::url ( ) const

Returns the request URL

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

◆ targetFilePath()

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

Returns the target filename path.

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

◆ downloadOffset()

off_t zyppng::NetworkRequest::downloadOffset ( ) const

Returns the requested start offset.

Definition at line 574 of file request.cc.

◆ reportedByteCount()

off_t 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.

Definition at line 579 of file request.cc.

◆ expectedByteCount()

off_t zyppng::NetworkRequest::expectedByteCount ( ) const

Returns the expected byte count that was passed to the constructor, zero if none was given.

Definition at line 584 of file request.cc.

◆ downloadedByteCount()

off_t zyppng::NetworkRequest::downloadedByteCount ( ) const

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

Definition at line 589 of file request.cc.

◆ setDigest()

void zyppng::NetworkRequest::setDigest ( std::shared_ptr< zypp::Digest dig)

Set a.

See also
zypp::Digest that is updated when data is written, can be used to validate the file contents with a checksum

Definition at line 597 of file request.cc.

◆ digest()

std::shared_ptr< zypp::Digest > zyppng::NetworkRequest::digest ( ) const

Returns the currently used.

See also
zypp::Digest, null if non was set.

Definition at line 612 of file request.cc.

◆ setExpectedChecksum()

void zyppng::NetworkRequest::setExpectedChecksum ( std::vector< unsigned char >  checksum)

Enables automated checking of downloaded contents against a checksum.

Only makes a difference if a

See also
zypp::Digest was with with
setDigest.
Note
expects checksum in byte NOT in string format

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

◆ state()

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

Returns the current state the HttpDownloadRequest is in.

Definition at line 617 of file request.cc.

◆ error()

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

Returns the last set Error.

Definition at line 622 of file request.cc.

◆ extendedErrorString()

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

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

In those cases its possible to query that information.

Definition at line 627 of file request.cc.

◆ hasError()

bool zyppng::NetworkRequest::hasError ( ) const

Checks if there was a error with the request.

Definition at line 636 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 641 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 655 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.

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

Friends And Related Function Documentation

◆ NetworkRequestDispatcher

friend class NetworkRequestDispatcher
friend

Definition at line 241 of file request.h.

◆ NetworkRequestDispatcherPrivate

friend class NetworkRequestDispatcherPrivate
friend

Definition at line 242 of file request.h.


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