| 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 | #if QT_NETWORK_REMOVED_SINCE(6, 7) |
| 101 | bool hasRawHeader(const QByteArray &headerName) const; |
| 102 | #endif |
| 103 | bool (QAnyStringView ) const; |
| 104 | QList<QByteArray> () const; |
| 105 | #if QT_NETWORK_REMOVED_SINCE(6, 7) |
| 106 | QByteArray rawHeader(const QByteArray &headerName) const; |
| 107 | #endif |
| 108 | QByteArray (QAnyStringView ) const; |
| 109 | |
| 110 | typedef QPair<QByteArray, QByteArray> ; |
| 111 | const QList<RawHeaderPair>& () const; |
| 112 | QHttpHeaders () const; |
| 113 | |
| 114 | // attributes |
| 115 | QVariant attribute(QNetworkRequest::Attribute code) const; |
| 116 | |
| 117 | #if QT_CONFIG(ssl) |
| 118 | QSslConfiguration sslConfiguration() const; |
| 119 | void setSslConfiguration(const QSslConfiguration &configuration); |
| 120 | void ignoreSslErrors(const QList<QSslError> &errors); |
| 121 | #endif |
| 122 | |
| 123 | public Q_SLOTS: |
| 124 | virtual void abort() = 0; |
| 125 | virtual void ignoreSslErrors(); |
| 126 | |
| 127 | Q_SIGNALS: |
| 128 | void socketStartedConnecting(); |
| 129 | void requestSent(); |
| 130 | void metaDataChanged(); |
| 131 | void finished(); |
| 132 | void errorOccurred(QNetworkReply::NetworkError); |
| 133 | #if QT_CONFIG(ssl) |
| 134 | void encrypted(); |
| 135 | void sslErrors(const QList<QSslError> &errors); |
| 136 | void preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator); |
| 137 | #endif |
| 138 | void redirected(const QUrl &url); |
| 139 | void redirectAllowed(); |
| 140 | |
| 141 | void uploadProgress(qint64 bytesSent, qint64 bytesTotal); |
| 142 | void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); |
| 143 | |
| 144 | protected: |
| 145 | explicit QNetworkReply(QObject *parent = nullptr); |
| 146 | QNetworkReply(QNetworkReplyPrivate &dd, QObject *parent); |
| 147 | virtual qint64 writeData(const char *data, qint64 len) override; |
| 148 | |
| 149 | void setOperation(QNetworkAccessManager::Operation operation); |
| 150 | void setRequest(const QNetworkRequest &request); |
| 151 | void setError(NetworkError errorCode, const QString &errorString); |
| 152 | void setFinished(bool); |
| 153 | void setUrl(const QUrl &url); |
| 154 | void (QNetworkRequest::KnownHeaders , const QVariant &value); |
| 155 | void (const QByteArray &, const QByteArray &value); |
| 156 | void (const QHttpHeaders &); |
| 157 | void (QHttpHeaders &&); |
| 158 | void (QHttpHeaders::WellKnownHeader name, QByteArrayView value); |
| 159 | void setAttribute(QNetworkRequest::Attribute code, const QVariant &value); |
| 160 | |
| 161 | #if QT_CONFIG(ssl) |
| 162 | virtual void sslConfigurationImplementation(QSslConfiguration &) const; |
| 163 | virtual void setSslConfigurationImplementation(const QSslConfiguration &); |
| 164 | virtual void ignoreSslErrorsImplementation(const QList<QSslError> &); |
| 165 | #endif |
| 166 | |
| 167 | private: |
| 168 | Q_DECLARE_PRIVATE(QNetworkReply) |
| 169 | }; |
| 170 | |
| 171 | QT_END_NAMESPACE |
| 172 | |
| 173 | QT_DECL_METATYPE_EXTERN_TAGGED(QNetworkReply::NetworkError, |
| 174 | QNetworkReply__NetworkError, Q_NETWORK_EXPORT) |
| 175 | |
| 176 | #endif |
| 177 | |