]> git.sur5r.net Git - minitube/blob - lib/http/src/httpreply.h
New upstream version 3.8
[minitube] / lib / http / src / httpreply.h
1 #ifndef HTTPREPLY_H
2 #define HTTPREPLY_H
3
4 #include <QtNetwork>
5
6 class HttpReply : public QObject {
7     Q_OBJECT
8
9 public:
10     HttpReply(QObject *parent = nullptr);
11     virtual QUrl url() const = 0;
12     virtual int statusCode() const = 0;
13     int isSuccessful() const;
14     virtual QString reasonPhrase() const;
15     virtual const QList<QNetworkReply::RawHeaderPair> headers() const;
16     virtual QByteArray header(const QByteArray &headerName) const;
17     virtual QByteArray body() const = 0;
18
19     template <typename Functor> HttpReply &onData(Functor lambda) {
20         connect(this, &HttpReply::data, this, lambda);
21         return *this;
22     }
23     template <typename Functor> HttpReply &onError(Functor lambda) {
24         connect(this, &HttpReply::error, this, lambda);
25         return *this;
26     }
27     template <typename Functor> HttpReply &onFinished(Functor lambda) {
28         connect(this, &HttpReply::finished, this, lambda);
29         return *this;
30     }
31
32 signals:
33     void data(const QByteArray &bytes);
34     void error(const QString &message);
35     void finished(const HttpReply &reply);
36 };
37
38 #endif // HTTPREPLY_H