1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtNetwork module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QHTTPNETWORKREPLY_H
43 #define QHTTPNETWORKREPLY_H
49 // This file is not part of the Qt API. It exists for the convenience
50 // of the Network Access API. This header file may change from
51 // version to version without notice, or even be removed.
55 #include <qplatformdefs.h>
58 #ifndef QT_NO_COMPRESS
62 #include <QtNetwork/qtcpsocket.h>
63 // it's safe to include these even if SSL support is not enabled
64 #include <QtNetwork/qsslsocket.h>
65 #include <QtNetwork/qsslerror.h>
67 #include <QtNetwork/qnetworkrequest.h>
68 #include <QtNetwork/qnetworkreply.h>
71 #include <private/qobject_p.h>
72 #include <private/qhttpnetworkheader_p.h>
73 #include <private/qhttpnetworkrequest_p.h>
74 #include <private/qauthenticator_p.h>
75 #include <private/qringbuffer_p.h>
76 #include <private/qbytedata_p.h>
80 class QHttpNetworkConnection;
81 class QHttpNetworkConnectionChannel;
82 class QHttpNetworkRequest;
83 class QHttpNetworkConnectionPrivate;
84 class QHttpNetworkReplyPrivate;
85 class Q_AUTOTEST_EXPORT QHttpNetworkReply : public QObject, public QHttpNetworkHeader
90 explicit QHttpNetworkReply(const QUrl &url = QUrl(), QObject *parent = 0);
91 virtual ~QHttpNetworkReply();
94 void setUrl(const QUrl &url);
96 int majorVersion() const;
97 int minorVersion() const;
99 qint64 contentLength() const;
100 void setContentLength(qint64 length);
102 QList<QPair<QByteArray, QByteArray> > header() const;
103 QByteArray headerField(const QByteArray &name, const QByteArray &defaultValue = QByteArray()) const;
104 void setHeaderField(const QByteArray &name, const QByteArray &data);
105 void parseHeader(const QByteArray &header); // mainly for testing
107 QHttpNetworkRequest request() const;
108 void setRequest(const QHttpNetworkRequest &request);
110 int statusCode() const;
111 void setStatusCode(int code);
113 QString errorString() const;
114 void setErrorString(const QString &error);
116 QString reasonPhrase() const;
118 qint64 bytesAvailable() const;
119 qint64 bytesAvailableNextBlock() const;
120 bool readAnyAvailable() const;
121 QByteArray readAny();
122 QByteArray readAll();
123 QByteArray read(qint64 amount);
124 qint64 sizeNextBlock();
125 void setDownstreamLimited(bool t);
126 void setReadBufferSize(qint64 size);
128 bool supportsUserProvidedDownloadBuffer();
129 void setUserProvidedDownloadBuffer(char*);
130 char* userProvidedDownloadBuffer();
132 bool isFinished() const;
134 bool isPipeliningUsed() const;
136 QHttpNetworkConnection* connection();
139 QSslConfiguration sslConfiguration() const;
140 void setSslConfiguration(const QSslConfiguration &config);
141 void ignoreSslErrors();
142 void ignoreSslErrors(const QList<QSslError> &errors);
145 void sslErrors(const QList<QSslError> &errors);
151 void finishedWithError(QNetworkReply::NetworkError errorCode, const QString &detail = QString());
152 void headerChanged();
153 void dataReadProgress(qint64 done, qint64 total);
154 void dataSendProgress(qint64 done, qint64 total);
155 void cacheCredentials(const QHttpNetworkRequest &request, QAuthenticator *authenticator);
156 #ifndef QT_NO_NETWORKPROXY
157 void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator);
159 void authenticationRequired(const QHttpNetworkRequest &request, QAuthenticator *authenticator);
161 Q_DECLARE_PRIVATE(QHttpNetworkReply)
162 friend class QHttpSocketEngine;
163 friend class QHttpNetworkConnection;
164 friend class QHttpNetworkConnectionPrivate;
165 friend class QHttpNetworkConnectionChannel;
169 class QHttpNetworkReplyPrivate : public QObjectPrivate, public QHttpNetworkHeaderPrivate
172 QHttpNetworkReplyPrivate(const QUrl &newUrl = QUrl());
173 ~QHttpNetworkReplyPrivate();
174 qint64 readStatus(QAbstractSocket *socket);
175 bool parseStatus(const QByteArray &status);
176 qint64 readHeader(QAbstractSocket *socket);
177 void parseHeader(const QByteArray &header);
178 qint64 readBody(QAbstractSocket *socket, QByteDataBuffer *out);
179 qint64 readBodyVeryFast(QAbstractSocket *socket, char *b);
180 qint64 readBodyFast(QAbstractSocket *socket, QByteDataBuffer *rb);
181 bool findChallenge(bool forProxy, QByteArray &challenge) const;
182 QAuthenticatorPrivate::Method authenticationMethod(bool isProxy) const;
184 void clearHttpLayerInformation();
186 qint64 readReplyBodyRaw(QAbstractSocket *in, QByteDataBuffer *out, qint64 size);
187 qint64 readReplyBodyChunked(QAbstractSocket *in, QByteDataBuffer *out);
188 qint64 getChunkSize(QAbstractSocket *in, qint64 *chunkSize);
190 bool shouldEmitSignals();
191 bool expectContent();
194 qint64 bytesAvailable() const;
196 bool isConnectionCloseEnabled();
199 void removeAutoDecompressHeader();
209 QHttpNetworkRequest request;
215 QString reasonPhrase;
218 qint64 totalProgress;
219 QByteArray fragment; // used for header, status, chunk header etc, not for reply data
220 bool chunkedTransferEncoding;
221 bool connectionCloseEnabled;
222 bool forceConnectionCloseEnabled;
224 qint64 currentChunkSize;
225 qint64 currentChunkRead;
226 qint64 readBufferMaxSize;
227 QPointer<QHttpNetworkConnection> connection;
228 QPointer<QHttpNetworkConnectionChannel> connectionChannel;
232 QByteDataBuffer responseData; // uncompressed body
233 QByteArray compressedData; // compressed body (temporary)
234 bool requestIsPrepared;
237 bool downstreamLimited;
239 char* userProvidedDownloadBuffer;
241 #ifndef QT_NO_COMPRESS
242 z_stream_s *inflateStrm;
243 qint64 uncompressBodyData(QByteDataBuffer *in, QByteDataBuffer *out);
252 //Q_DECLARE_METATYPE(QHttpNetworkReply)
257 #endif // QHTTPNETWORKREPLY_H