RestLink 2.2.0
Powerfull Rest Client for Qt
Loading...
Searching...
No Matches
response.h
1#ifndef RESTLINK_RESPONSE_H
2#define RESTLINK_RESPONSE_H
3
4#include <RestLink/global.h>
5#include <RestLink/responsebase.h>
6#include <RestLink/api.h>
7
8#include <QtCore/qobject.h>
9
10class QNetworkRequest;
11class QNetworkReply;
12class QSslError;
13
14class QJsonParseError;
15
16namespace RestLink {
17
18class Request;
19
20class ResponsePrivate;
21class NetworkResponsePrivate;
22class RESTLINK_EXPORT Response : public ResponseBase
23{
24 Q_OBJECT
25 Q_PROPERTY(QString endpoint READ endpoint CONSTANT FINAL)
26 Q_PROPERTY(int method READ method CONSTANT FINAL)
27 Q_PROPERTY(QUrl url READ url CONSTANT FINAL)
28 Q_PROPERTY(bool running READ isRunning NOTIFY finished FINAL)
29 Q_PROPERTY(bool finished READ isFinished NOTIFY finished FINAL)
30 Q_PROPERTY(bool success READ isSuccess NOTIFY finished FINAL)
31 Q_PROPERTY(bool hasHttpStatusCode READ hasHttpStatusCode NOTIFY finished FINAL)
32 Q_PROPERTY(int httpStatusCode READ httpStatusCode NOTIFY finished FINAL)
33 Q_PROPERTY(QString httpReasonPhrase READ httpReasonPhrase NOTIFY finished FINAL)
34 Q_PROPERTY(QByteArrayList headerList READ headerList NOTIFY finished FINAL)
35 Q_PROPERTY(bool hasNetworkError READ hasNetworkError NOTIFY finished FINAL)
36 Q_PROPERTY(int networkError READ networkError NOTIFY networkErrorOccured FINAL)
37 Q_PROPERTY(QString networkErrorString READ networkErrorString NOTIFY networkErrorOccured FINAL)
38 Q_PROPERTY(QByteArray body READ body NOTIFY finished FINAL)
39
40public:
41 virtual ~Response();
42
43 QString endpoint() const;
44 Request request() const;
45
46 virtual AbstractRequestHandler::Method method() const = 0;
47 Api *api() const;
48
49 QUrl url() const;
50 virtual QNetworkRequest networkRequest() const = 0;
51
52 inline bool isRunning() const
53 { return !isFinished(); }
54 virtual bool isFinished() const = 0;
55
56 inline bool isSuccess() const
57 { return !hasNetworkError() && isHttpStatusSuccess(); }
58
59 bool isHttpStatusSuccess() const;
60 bool hasHttpStatusCode() const;
61 virtual int httpStatusCode() const = 0;
62 virtual QString httpReasonPhrase() const;
63
64 virtual bool hasHeader(const QByteArray &name) const;
65 Q_INVOKABLE virtual QByteArray header(const QByteArray &name) const = 0;
66 virtual QByteArrayList headerList() const = 0;
67
68 inline bool hasNetworkError() const { return networkError() != 0; }
69 virtual int networkError() const;
70 virtual QString networkErrorString() const;
71
72 virtual QNetworkReply *networkReply() const = 0;
73
74protected:
75 Response(ResponsePrivate *d, QObject *parent);
76
77 void setRequest(const Request &request);
78
79 QByteArray body();
80
81 QScopedPointer<ResponsePrivate> d_ptr;
82
83public slots:
84 virtual void ignoreSslErrors();
85 virtual void abort() = 0;
86
87signals:
88 void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
89 void uploadProgress(qint64 bytesSent, qint64 bytesTotal);
90 void networkErrorOccured(int error);
91 void finished();
92
93 void sslErrorsOccured(const QList<QSslError> &errors);
94
96};
97
98}
99
100#endif // RESTLINK_RESPONSE_H