libzypp  17.38.7
request.h
Go to the documentation of this file.
1 #ifndef ZYPP_NG_MEDIA_CURL_REQUEST_H_INCLUDED
2 #define ZYPP_NG_MEDIA_CURL_REQUEST_H_INCLUDED
3 
5 #include <zypp-curl/ng/network/TransferSettings>
7 #include <zypp-core/ng/base/Base>
8 #include <zypp-core/ng/core/Url>
9 #include <zypp-core/ng/core/ByteArray>
12 #include <zypp-core/base/Flags.h>
13 #include <zypp-core/ByteCount.h>
14 #include <optional>
15 #include <vector>
16 #include <chrono>
17 #include <any>
18 
19 namespace zypp {
20  class Digest;
21  class CheckSum;
22 
23  namespace media {
24  class AuthData;
25  }
26 }
27 
28 namespace zyppng {
29 
31 
32  class NetworkRequestDispatcher;
33  class NetworkRequestPrivate;
34 
42  class NetworkRequest : public Base
43  {
44  public:
45 
46  using Ptr = std::shared_ptr<NetworkRequest>;
47  using WeakPtr = std::weak_ptr<NetworkRequest>;
48  using DigestPtr = std::shared_ptr<zypp::Digest>;
50 
51  enum State {
52  Pending, //< waiting to be dispatched
53  Running, //< currently running
54  Finished, //< finished successfully
55  Error, //< Error, use error function to figure out the issue
56  };
57 
58  enum Priority {
59  Normal, //< Requests with normal priority will be enqueued as they come in
60  High, //< Request with high priority will be moved to the front of the queue
61  Critical = 100, //< Those requests will be enqueued as fast as possible, even before High priority requests, this should be used only if requests needs to start immediately
62  };
63 
64  enum FileMode {
65  WriteExclusive, //< the request will create its own file, overwriting anything that already exists
66  WriteShared //< the request will create or open the file in shared mode and only write between \a start and \a len
67  };
68 
69  enum OptionBits {
70  Default = 0x00, //< no special options, just do a normal download
71  HeadRequest = 0x01, //< only request the header part of the file
72  ConnectionTest = 0x02 //< only connect to collect connection speed information
73  };
75 
77 
78  struct Timings {
79  std::chrono::microseconds namelookup;
80  std::chrono::microseconds connect;
81  std::chrono::microseconds appconnect;
82  std::chrono::microseconds pretransfer;
83  std::chrono::microseconds total;
84  std::chrono::microseconds redirect;
85  };
86 
93  ~NetworkRequest() override;
94 
101 
103 
109  void setPriority ( Priority prio, bool triggerReschedule = true );
110 
114  Priority priority ( ) const;
115 
121  void setOptions ( Options opt );
122 
126  Options options () const;
127 
132  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 = {} );
133 
134  void addRequestRange ( Range &&range );
135 
140  bool setExpectedFileChecksum( const zypp::CheckSum &expected );
141 
146  void resetRequestRanges ( );
147 
148  std::vector<Range> failedRanges () const;
149  const std::vector<Range> &requestedRanges () const;
150 
154  const std::string &lastRedirectInfo() const;
155 
162  void *nativeHandle () const;
163 
168  std::optional<Timings> timings () const;
169 
174  std::vector<char> peekData ( off_t offset, size_t count ) const;
175 
179  Url url () const;
180 
185  void setUrl ( const Url & url );
186 
190  const zypp::Pathname & targetFilePath () const;
191 
196  void setTargetFilePath ( const zypp::Pathname &path );
197 
201  FileMode fileOpenMode () const;
202 
207  void setFileOpenMode ( FileMode mode );
208 
213  std::string contentType () const;
214 
222 
227 
233 
237  State state () const;
238 
242  NetworkRequestError error () const;
243 
248  std::string extendedErrorString() const;
249 
253  bool hasError () const;
254 
259  bool addRequestHeader(const std::string &header );
260 
264  const zypp::Pathname &cookieFile() const;
265 
271 
275  SignalProxy<void ( NetworkRequest &req )> sigStarted ();
276 
280  SignalProxy<void ( NetworkRequest &req, zypp::ByteCount count )> sigBytesDownloaded ();
281 
287  SignalProxy<void ( NetworkRequest &req, off_t dltotal, off_t dlnow, off_t ultotal, off_t ulnow )> sigProgress ();
288 
295  SignalProxy<void ( NetworkRequest &req, const NetworkRequestError &err)> sigFinished ( );
296 
297  private:
301  };
302 
303 }
304 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(zyppng::NetworkRequest::Options);
305 
306 #endif
std::optional< Timings > timings() const
After the request is finished query the timings that were collected during download.
Definition: request.cc:879
void * nativeHandle() const
Definition: request.cc:874
zypp::ByteCount reportedByteCount() const
Returns the number of bytes that are reported from the backend as the full download size...
Definition: request.cc:966
const std::vector< Range > & requestedRanges() const
Definition: request.cc:864
std::chrono::microseconds connect
Definition: request.h:80
std::weak_ptr< Base > WeakPtr
Definition: base.h:67
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:799
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:1069
Store and operate with byte count.
Definition: ByteCount.h:31
const std::string & lastRedirectInfo() const
Definition: request.cc:869
std::chrono::microseconds pretransfer
Definition: request.h:82
zypp::ByteCount downloadedByteCount() const
Returns the number of already downloaded bytes as reported by the backend.
Definition: request.cc:980
friend class NetworkRequestDispatcher
Definition: request.h:298
NetworkRequest(Url url, zypp::Pathname targetFile, FileMode fMode=WriteExclusive)
Definition: request.cc:753
std::chrono::microseconds appconnect
Definition: request.h:81
void setOptions(Options opt)
Definition: request.cc:789
TransferSettings & transferSettings()
Definition: request.cc:995
void setExpectedFileSize(zypp::ByteCount expectedFileSize)
Definition: request.cc:766
void setFileOpenMode(FileMode mode)
Sets the file open mode to mode.
Definition: request.cc:950
bool hasError() const
Checks if there was a error with the request.
Definition: request.cc:1035
const zypp::Pathname & cookieFile() const
Definition: request.cc:1054
void setUrl(const Url &url)
This will change the URL of the request.
Definition: request.cc:923
std::chrono::microseconds namelookup
Definition: request.h:79
bool addRequestHeader(const std::string &header)
Definition: request.cc:1040
zypp::media::AuthData AuthData
Definition: authdata.h:21
std::vector< char > peekData(off_t offset, size_t count) const
Definition: request.cc:907
NetworkRequestError error() const
Returns the last set Error.
Definition: request.cc:1019
UByteArray CheckSumBytes
Definition: request.h:49
std::string extendedErrorString() const
In some cases, curl can provide extended error information collected at runtime.
Definition: request.cc:1027
zypp::media::TransferSettings TransferSettings
Priority priority() const
Definition: request.cc:784
zypp::UByteArray UByteArray
Definition: bytearray.h:22
const zypp::Pathname & targetFilePath() const
Returns the target filename path.
Definition: request.cc:932
zypp::Url Url
Definition: url.h:15
void setTargetFilePath(const zypp::Pathname &path)
Changes the target file path of the download.
Definition: request.cc:937
CurlMultiPartHandler::Range Range
Definition: request.h:76
void setCookieFile(zypp::Pathname cookieFile)
Definition: request.cc:1059
std::string contentType() const
Returns the content type as reported from the server.
Definition: request.cc:958
ZYPP_DECLARE_OPERATORS_FOR_FLAGS(zyppng::NetworkRequest::Options)
ZYPP_DECLARE_FLAGS(Options, OptionBits)
bool setExpectedFileChecksum(const zypp::CheckSum &expected)
Definition: request.cc:822
#define ZYPP_DECLARE_PRIVATE(Class)
Definition: zyppglobal.h:80
std::chrono::microseconds total
Definition: request.h:83
void setPriority(Priority prio, bool triggerReschedule=true)
Definition: request.cc:776
State state() const
Returns the current state the HttpDownloadRequest is in.
Definition: request.cc:1000
Options options() const
Definition: request.cc:794
std::chrono::microseconds redirect
Definition: request.h:84
std::shared_ptr< zypp::Digest > DigestPtr
Definition: request.h:48
SignalProxy< void(NetworkRequest &req, const NetworkRequestError &err)> sigFinished()
Signals that the download finished.
Definition: request.cc:1079
SignalProxy< void(NetworkRequest &req)> sigStarted()
Signals that the dispatcher dequeued the request and actually starts downloading data.
Definition: request.cc:1064
zypp::ByteCount expectedFileSize() const
Definition: request.cc:771
FileMode fileOpenMode() const
Returns the currently configured file open mode.
Definition: request.cc:945
std::vector< Range > failedRanges() const
Definition: request.cc:847
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
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:1074
~NetworkRequest() override
Definition: request.cc:758
Url manipulation class.
Definition: Url.h:92
std::shared_ptr< Base > Ptr
Definition: base.h:66