1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the QtNetwork module of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 21 ** packaging of this file. Please review the following information to 22 ** ensure the GNU Lesser General Public License version 3 requirements 23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 24 ** 25 ** GNU General Public License Usage 26 ** Alternatively, this file may be used under the terms of the GNU 27 ** General Public License version 2.0 or (at your option) the GNU General 28 ** Public license version 3 or any later version approved by the KDE Free 29 ** Qt Foundation. The licenses are as published by the Free Software 30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 31 ** included in the packaging of this file. Please review the following 32 ** information to ensure the GNU General Public License requirements will 33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and 34 ** https://www.gnu.org/licenses/gpl-3.0.html. 35 ** 36 ** $QT_END_LICENSE$ 37 ** 38 ****************************************************************************/ 39 40 #ifndef QNETWORKREPLY_H 41 #define QNETWORKREPLY_H 42 43 #include <QtNetwork/qtnetworkglobal.h> 44 #include <QtCore/QIODevice> 45 #include <QtCore/QString> 46 #include <QtCore/QVariant> 47 48 #include <QtNetwork/QNetworkRequest> 49 #include <QtNetwork/QNetworkAccessManager> 50 51 QT_BEGIN_NAMESPACE 52 53 54 class QUrl; 55 class QVariant; 56 class QAuthenticator; 57 class QSslConfiguration; 58 class QSslError; 59 class QSslPreSharedKeyAuthenticator; 60 61 class QNetworkReplyPrivate; 62 class Q_NETWORK_EXPORT QNetworkReply: public QIODevice 63 { 64 Q_OBJECT 65 public: 66 enum NetworkError { 67 NoError = 0, 68 69 // network layer errors [relating to the destination server] (1-99): 70 ConnectionRefusedError = 1, 71 RemoteHostClosedError, 72 HostNotFoundError, 73 TimeoutError, 74 OperationCanceledError, 75 SslHandshakeFailedError, 76 TemporaryNetworkFailureError, 77 NetworkSessionFailedError, 78 BackgroundRequestNotAllowedError, 79 TooManyRedirectsError, 80 InsecureRedirectError, 81 UnknownNetworkError = 99, 82 83 // proxy errors (101-199): 84 ProxyConnectionRefusedError = 101, 85 ProxyConnectionClosedError, 86 ProxyNotFoundError, 87 ProxyTimeoutError, 88 ProxyAuthenticationRequiredError, 89 UnknownProxyError = 199, 90 91 // content errors (201-299): 92 ContentAccessDenied = 201, 93 ContentOperationNotPermittedError, 94 ContentNotFoundError, 95 AuthenticationRequiredError, 96 ContentReSendError, 97 ContentConflictError, 98 ContentGoneError, 99 UnknownContentError = 299, 100 101 // protocol errors 102 ProtocolUnknownError = 301, 103 ProtocolInvalidOperationError, 104 ProtocolFailure = 399, 105 106 // Server side errors (401-499) 107 InternalServerError = 401, 108 OperationNotImplementedError, 109 ServiceUnavailableError, 110 UnknownServerError = 499 111 }; 112 Q_ENUM(NetworkError) 113 114 ~QNetworkReply(); 115 116 // reimplemented from QIODevice 117 virtual void close() override; 118 virtual bool isSequential() const override; 119 120 // like QAbstractSocket: 121 qint64 readBufferSize() const; 122 virtual void setReadBufferSize(qint64 size); 123 124 QNetworkAccessManager *manager() const; 125 QNetworkAccessManager::Operation operation() const; 126 QNetworkRequest request() const; 127 NetworkError error() const; 128 bool isFinished() const; 129 bool isRunning() const; 130 QUrl url() const; 131 132 // "cooked" headers 133 QVariant header(QNetworkRequest::KnownHeaders header) const; 134 135 // raw headers: 136 bool hasRawHeader(const QByteArray &headerName) const; 137 QList<QByteArray> rawHeaderList() const; 138 QByteArray rawHeader(const QByteArray &headerName) const; 139 140 typedef QPair<QByteArray, QByteArray> RawHeaderPair; 141 const QList<RawHeaderPair>& rawHeaderPairs() const; 142 143 // attributes 144 QVariant attribute(QNetworkRequest::Attribute code) const; 145 146 #if QT_CONFIG(ssl) 147 QSslConfiguration sslConfiguration() const; 148 void setSslConfiguration(const QSslConfiguration &configuration); 149 void ignoreSslErrors(const QList<QSslError> &errors); 150 #endif 151 152 public Q_SLOTS: 153 virtual void abort() = 0; 154 virtual void ignoreSslErrors(); 155 156 Q_SIGNALS: 157 void metaDataChanged(); 158 void finished(); 159 #if QT_DEPRECATED_SINCE(5,15) 160 QT_DEPRECATED_NETWORK_API_5_15_X("Use QNetworkReply::errorOccurred(QNetworkReply::NetworkError) instead") 161 void error(QNetworkReply::NetworkError); 162 #endif 163 void errorOccurred(QNetworkReply::NetworkError); 164 #if QT_CONFIG(ssl) 165 void encrypted(); 166 void sslErrors(const QList<QSslError> &errors); 167 void preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator); 168 #endif 169 void redirected(const QUrl &url); 170 void redirectAllowed(); 171 172 void uploadProgress(qint64 bytesSent, qint64 bytesTotal); 173 void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); 174 175 protected: 176 explicit QNetworkReply(QObject *parent = nullptr); 177 QNetworkReply(QNetworkReplyPrivate &dd, QObject *parent); 178 virtual qint64 writeData(const char *data, qint64 len) override; 179 180 void setOperation(QNetworkAccessManager::Operation operation); 181 void setRequest(const QNetworkRequest &request); 182 void setError(NetworkError errorCode, const QString &errorString); 183 void setFinished(bool); 184 void setUrl(const QUrl &url); 185 void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value); 186 void setRawHeader(const QByteArray &headerName, const QByteArray &value); 187 void setAttribute(QNetworkRequest::Attribute code, const QVariant &value); 188 189 #if QT_CONFIG(ssl) 190 virtual void sslConfigurationImplementation(QSslConfiguration &) const; 191 virtual void setSslConfigurationImplementation(const QSslConfiguration &); 192 virtual void ignoreSslErrorsImplementation(const QList<QSslError> &); 193 #endif 194 195 private: 196 Q_DECLARE_PRIVATE(QNetworkReply) 197 }; 198 199 QT_END_NAMESPACE 200 201 Q_DECLARE_METATYPE(QNetworkReply::NetworkError) 202 203 #endif 204