Base class for network requests which are processed in the network access manager.
More...
#include <networkrequestbase.h>
|
void | start () noexcept |
| Start downloading the requested content. More...
|
|
void | abort () noexcept |
| Abort downloading the requested content. More...
|
|
Base class for network requests which are processed in the network access manager.
This class lets you execute a network request without blocking the main application thread. After creating an object derived from librepcb::NetworkRequestBase, you can connect to signals of that class to track the progress of the request. Then you need to call start() to start the request processing.
- Note
- You need to ensure that an instance of librepcb::NetworkAccessManager exists while starting a new network request. Otherwise the request will fail. Read the documentation of librepcb::NetworkAccessManager for more information.
- See also
- librepcb::NetworkAccessManager
◆ NetworkRequestBase() [1/3]
◆ NetworkRequestBase() [2/3]
◆ NetworkRequestBase() [3/3]
◆ ~NetworkRequestBase()
◆ setHeaderField()
void setHeaderField |
( |
const QByteArray & |
name, |
|
|
const QByteArray & |
value |
|
) |
| |
|
noexcept |
Set a HTTP header field for the network request.
- Parameters
-
name | Header field name |
value | Header field value |
◆ setCacheLoadControl()
void setCacheLoadControl |
( |
QNetworkRequest::CacheLoadControl |
value | ) |
|
|
noexcept |
Set the cache load control attribute.
Allows to control the caching behavior, e.g. enforcing download only from cache but not from the network. For details, see documentation of QNetworkRequest::setAttribute()
.
- Parameters
-
value | The new cache control value |
◆ setExpectedReplyContentSize()
void setExpectedReplyContentSize |
( |
qint64 |
bytes | ) |
|
|
noexcept |
Set the expected size of the requested content.
If set, this size will be used to calculate the download progress in percent in case that there is no "Content-Length" attribute in the received HTTP header.
- Parameters
-
bytes | Expected content size of the reply in bytes |
◆ setMinimumCacheTime()
void setMinimumCacheTime |
( |
int |
seconds | ) |
|
|
noexcept |
Set the minimum time the request should be cached.
This allows to cache requests longer than specified in response headers, which is useful for URLs not under our own control where rather uncritical content like images are downloaded from. If the response header specifies a higher max-age value, it has priority so this method has no effect.
- Parameters
-
seconds | Minimum cache time in seconds (default is 0) |
◆ useBrowserUserAgent()
void useBrowserUserAgent |
( |
| ) |
|
|
noexcept |
Use a typical browser user agent for this request.
It turned out at least st.com blocks downloading files if the request is not coming from a browser. For downloading datasheets we don't care about the user agent so let's just work arount this issue by using a well-known user agent.
◆ operator=()
◆ start
Start downloading the requested content.
- Warning
- It is not save to access this object after calling this method! The object will be moved to another thread and will be deleted after an error occurs or the request succeeds. Any further access to the pointer which you have received from the constructor is unsave and could cause an application crash.
◆ abort
Abort downloading the requested content.
- Warning
- Because calling this method makes only sense after calling start(), but which is unsave as described in start(), this method must only be used indirectly with the signals/slots concept of Qt (Qt automatically disconnects the callers signal from this slot as soon as this object gets destroyed, so the connection is always safe).
◆ startRequested
Internal signal, don't use it from outside.
◆ progressState
void progressState |
( |
QString |
state | ) |
|
|
signal |
Reply progress / state changed signal.
This signal shows which actions are executed. Or in other words, it shows the current state of the request processing.
- Parameters
-
state | Short description about the current action/state |
◆ progressPercent
void progressPercent |
( |
int |
percent | ) |
|
|
signal |
Reply content download progress signal (simple)
- Parameters
-
percent | (Estimated) progress in percent (0..100) |
◆ progress
void progress |
( |
qint64 |
bytesReceived, |
|
|
qint64 |
bytesTotal, |
|
|
int |
percent |
|
) |
| |
|
signal |
Reply content download progress signal (extended)
- Parameters
-
bytesReceived | Count of bytes received |
bytesTotal | Count of total bytes (-1 if unknown) |
percent | (Estimated) progress in percent (0..100) |
◆ aborted
Request aborted signal (emitted right before finished())
◆ succeeded
Request succeeded signal (emitted right before finished())
◆ errored
void errored |
( |
QString |
errorMsg | ) |
|
|
signal |
Request errored signal (emitted right before finished())
- Parameters
-
◆ finished
void finished |
( |
bool |
success | ) |
|
|
signal |
Request finished signal.
This signal is emitted right after aborted(), succeeded() or errored().
- Parameters
-
success | True if succeeded, false if aborted or errored |
◆ prepareRequest()
virtual void prepareRequest |
( |
| ) |
|
|
pure virtual |
◆ finalizeRequest()
virtual void finalizeRequest |
( |
| ) |
|
|
pure virtual |
◆ emitSuccessfullyFinishedSignals()
virtual void emitSuccessfullyFinishedSignals |
( |
QString |
contentType | ) |
|
|
pure virtualnoexcept |
◆ fetchNewData()
virtual void fetchNewData |
( |
QIODevice & |
device | ) |
|
|
pure virtualnoexcept |
◆ executeRequest()
◆ uploadProgressSlot()
void uploadProgressSlot |
( |
qint64 |
bytesSent, |
|
|
qint64 |
bytesTotal |
|
) |
| |
|
privatenoexcept |
◆ replyDownloadProgressSlot()
void replyDownloadProgressSlot |
( |
qint64 |
bytesReceived, |
|
|
qint64 |
bytesTotal |
|
) |
| |
|
privatenoexcept |
◆ replyReadyReadSlot()
void replyReadyReadSlot |
( |
| ) |
|
|
privatenoexcept |
◆ replyErrorSlot()
void replyErrorSlot |
( |
QNetworkReply::NetworkError |
code | ) |
|
|
privatenoexcept |
◆ replySslErrorsSlot()
void replySslErrorsSlot |
( |
const QList< QSslError > & |
errors | ) |
|
|
privatenoexcept |
◆ replyFinishedSlot()
void replyFinishedSlot |
( |
| ) |
|
|
privatenoexcept |
◆ finalize()
void finalize |
( |
const QString & |
errorMsg, |
|
|
const QString & |
contentType = QString() |
|
) |
| |
|
privatenoexcept |
◆ formatFileSize()
QString formatFileSize |
( |
qint64 |
bytes | ) |
|
|
staticprivatenoexcept |
◆ getUserAgent()
◆ mUrl
◆ mPostData
◆ mExpectedContentSize
qint64 mExpectedContentSize |
|
protected |
◆ mMinimumCacheTime
◆ mRedirectedUrls
QList<QUrl> mRedirectedUrls |
|
protected |
◆ mRequest
◆ mReply
QScopedPointer<QNetworkReply> mReply |
|
protected |
◆ mStarted
◆ mAborted
◆ mErrored
◆ mFinished
The documentation for this class was generated from the following files: