1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QNETWORKREPLY_H |
5 | #define QNETWORKREPLY_H |
6 | |
7 | #include <QtNetwork/qtnetworkglobal.h> |
8 | #include <QtCore/QIODevice> |
9 | #include <QtCore/QString> |
10 | #include <QtCore/QVariant> |
11 | |
12 | #include <QtNetwork/QNetworkRequest> |
13 | #include <QtNetwork/QNetworkAccessManager> |
14 | |
15 | QT_BEGIN_NAMESPACE |
16 | |
17 | |
18 | class QUrl; |
19 | class QVariant; |
20 | class QAuthenticator; |
21 | class QSslConfiguration; |
22 | class QSslError; |
23 | class QSslPreSharedKeyAuthenticator; |
24 | |
25 | class QNetworkReplyPrivate; |
26 | class Q_NETWORK_EXPORT QNetworkReply: public QIODevice |
27 | { |
28 | Q_OBJECT |
29 | public: |
30 | enum NetworkError { |
31 | NoError = 0, |
32 | |
33 | // network layer errors [relating to the destination server] (1-99): |
34 | ConnectionRefusedError = 1, |
35 | RemoteHostClosedError, |
36 | HostNotFoundError, |
37 | TimeoutError, |
38 | OperationCanceledError, |
39 | SslHandshakeFailedError, |
40 | TemporaryNetworkFailureError, |
41 | NetworkSessionFailedError, |
42 | BackgroundRequestNotAllowedError, |
43 | TooManyRedirectsError, |
44 | InsecureRedirectError, |
45 | UnknownNetworkError = 99, |
46 | |
47 | // proxy errors (101-199): |
48 | ProxyConnectionRefusedError = 101, |
49 | ProxyConnectionClosedError, |
50 | ProxyNotFoundError, |
51 | ProxyTimeoutError, |
52 | ProxyAuthenticationRequiredError, |
53 | UnknownProxyError = 199, |
54 | |
55 | // content errors (201-299): |
56 | ContentAccessDenied = 201, |
57 | ContentOperationNotPermittedError, |
58 | ContentNotFoundError, |
59 | AuthenticationRequiredError, |
60 | ContentReSendError, |
61 | ContentConflictError, |
62 | ContentGoneError, |
63 | UnknownContentError = 299, |
64 | |
65 | // protocol errors |
66 | ProtocolUnknownError = 301, |
67 | ProtocolInvalidOperationError, |
68 | ProtocolFailure = 399, |
69 | |
70 | // Server side errors (401-499) |
71 | InternalServerError = 401, |
72 | OperationNotImplementedError, |
73 | ServiceUnavailableError, |
74 | UnknownServerError = 499 |
75 | }; |
76 | Q_ENUM(NetworkError) |
77 | |
78 | ~QNetworkReply(); |
79 | |
80 | // reimplemented from QIODevice |
81 | virtual void close() override; |
82 | virtual bool isSequential() const override; |
83 | |
84 | // like QAbstractSocket: |
85 | qint64 readBufferSize() const; |
86 | virtual void setReadBufferSize(qint64 size); |
87 | |
88 | QNetworkAccessManager *manager() const; |
89 | QNetworkAccessManager::Operation operation() const; |
90 | QNetworkRequest request() const; |
91 | NetworkError error() const; |
92 | bool isFinished() const; |
93 | bool isRunning() const; |
94 | QUrl url() const; |
95 | |
96 | // "cooked" headers |
97 | QVariant (QNetworkRequest::KnownHeaders ) const; |
98 | |
99 | // raw headers: |
100 | bool (const QByteArray &) const; |
101 | QList<QByteArray> () const; |
102 | QByteArray (const QByteArray &) const; |
103 | |
104 | typedef QPair<QByteArray, QByteArray> ; |
105 | const QList<RawHeaderPair>& () const; |
106 | |
107 | // attributes |
108 | QVariant attribute(QNetworkRequest::Attribute code) const; |
109 | |
110 | #if QT_CONFIG(ssl) |
111 | QSslConfiguration sslConfiguration() const; |
112 | void setSslConfiguration(const QSslConfiguration &configuration); |
113 | void ignoreSslErrors(const QList<QSslError> &errors); |
114 | #endif |
115 | |
116 | public Q_SLOTS: |
117 | virtual void abort() = 0; |
118 | virtual void ignoreSslErrors(); |
119 | |
120 | Q_SIGNALS: |
121 | void socketStartedConnecting(); |
122 | void requestSent(); |
123 | void metaDataChanged(); |
124 | void finished(); |
125 | void errorOccurred(QNetworkReply::NetworkError); |
126 | #if QT_CONFIG(ssl) |
127 | void encrypted(); |
128 | void sslErrors(const QList<QSslError> &errors); |
129 | void preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator); |
130 | #endif |
131 | void redirected(const QUrl &url); |
132 | void redirectAllowed(); |
133 | |
134 | void uploadProgress(qint64 bytesSent, qint64 bytesTotal); |
135 | void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); |
136 | |
137 | protected: |
138 | explicit QNetworkReply(QObject *parent = nullptr); |
139 | QNetworkReply(QNetworkReplyPrivate &dd, QObject *parent); |
140 | virtual qint64 writeData(const char *data, qint64 len) override; |
141 | |
142 | void setOperation(QNetworkAccessManager::Operation operation); |
143 | void setRequest(const QNetworkRequest &request); |
144 | void setError(NetworkError errorCode, const QString &errorString); |
145 | void setFinished(bool); |
146 | void setUrl(const QUrl &url); |
147 | void (QNetworkRequest::KnownHeaders , const QVariant &value); |
148 | void (const QByteArray &, const QByteArray &value); |
149 | void setAttribute(QNetworkRequest::Attribute code, const QVariant &value); |
150 | |
151 | #if QT_CONFIG(ssl) |
152 | virtual void sslConfigurationImplementation(QSslConfiguration &) const; |
153 | virtual void setSslConfigurationImplementation(const QSslConfiguration &); |
154 | virtual void ignoreSslErrorsImplementation(const QList<QSslError> &); |
155 | #endif |
156 | |
157 | private: |
158 | Q_DECLARE_PRIVATE(QNetworkReply) |
159 | }; |
160 | |
161 | QT_END_NAMESPACE |
162 | |
163 | QT_DECL_METATYPE_EXTERN_TAGGED(QNetworkReply::NetworkError, |
164 | QNetworkReply__NetworkError, Q_NETWORK_EXPORT) |
165 | |
166 | #endif |
167 | |