KanoopProtocolQt 1.2.3
Qt HTTP operations and MQTT client library
Loading...
Searching...
No Matches
httpget.h
1#ifndef HTTPGET_H
2#define HTTPGET_H
3#include <Kanoop/kanoopprotocol.h>
4#include <Kanoop/http/httpoperation.h>
5
6/** @brief HTTP GET operation executed asynchronously on a dedicated thread. */
7class LIBKANOOPPROTOCOL_EXPORT HttpGet : public HttpOperation
8{
9 Q_OBJECT
10public:
11 /** @brief Construct an HTTP GET operation for the given URL.
12 * @param url The target URL. */
13 HttpGet(const QString& url);
14
15 /** @brief Add a query parameter to the GET request.
16 * @param key The parameter name.
17 * @param value The parameter value. */
18 void addParameter(const QString& key, const QString& value);
19
20 /**
21 * @brief streamingRead
22 * Set to true to return the response piece by piece as available
23 * using the `dataAvailable()` signal
24 * @return True if streaming read mode is enabled.
25 */
26 bool streamingRead() const { return _streamingRead; }
27
28 /** @brief Enable or disable streaming read mode.
29 * @param value True to enable streaming reads via the dataAvailable() signal. */
30 void setStreamingRead(bool value) { _streamingRead = value; }
31
32signals:
33 /** @brief Emitted when a chunk of data is available during a streaming read.
34 * @param data The received data chunk. */
35 void dataAvailable(const QByteArray& data);
36
37 /** @brief Emitted to report download progress.
38 * @param bytesReceived The number of bytes received so far.
39 * @param bytesTotal The total number of bytes expected, or -1 if unknown. */
40 void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
41
42protected:
43 /** @brief Execute the HTTP GET request. */
44 virtual void execute() override;
45
46 /** @brief Hook called before the GET request is sent. */
47 virtual void preGetHook(QNetworkRequest*) {}
48
49 /** @brief Hook called after the GET reply is received.
50 * @param reply The network reply object. */
51 virtual void postGetHook(QNetworkReply* reply) { Q_UNUSED(reply) }
52
53 /** @brief Hook called after the network reply is processed.
54 * @param reply The network reply object. */
55 virtual void postReplyHook(QNetworkReply*reply) override;
56
57private:
58 QList<KeyValuePair> _parameters;
59 bool _streamingRead = false;
60
61private slots:
62 void onStreamingReadyRead();
63};
64
65#endif // HTTPGET_H
HTTP GET operation executed asynchronously on a dedicated thread.
Definition httpget.h:8
bool streamingRead() const
streamingRead Set to true to return the response piece by piece as available using the dataAvailable(...
Definition httpget.h:26
void dataAvailable(const QByteArray &data)
Emitted when a chunk of data is available during a streaming read.
virtual void preGetHook(QNetworkRequest *)
Hook called before the GET request is sent.
Definition httpget.h:47
void setStreamingRead(bool value)
Enable or disable streaming read mode.
Definition httpget.h:30
virtual void postGetHook(QNetworkReply *reply)
Hook called after the GET reply is received.
Definition httpget.h:51
virtual void postReplyHook(QNetworkReply *reply) override
Hook called after the network reply is processed.
virtual void execute() override
Execute the HTTP GET request.
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
Emitted to report download progress.
HttpGet(const QString &url)
Construct an HTTP GET operation for the given URL.
void addParameter(const QString &key, const QString &value)
Add a query parameter to the GET request.
Base class for HTTP operations executed asynchronously on a dedicated thread.