summaryrefslogtreecommitdiffstats
path: root/src/network/access
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2009-06-25 13:45:07 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2009-06-25 14:17:37 (GMT)
commitd5b75962ee2e22b5a6b061430f936fc663d7122b (patch)
tree03a939983a9e946af8612a258f0dd043646fe5cf /src/network/access
parent553fb1b2e636cf14a193b1ca15bd08f755a452b3 (diff)
downloadQt-d5b75962ee2e22b5a6b061430f936fc663d7122b.zip
Qt-d5b75962ee2e22b5a6b061430f936fc663d7122b.tar.gz
Qt-d5b75962ee2e22b5a6b061430f936fc663d7122b.tar.bz2
QNAM HTTP Code: Uncluttering functions
Uncluttered and duplicated some function to make it more clear what is happening. Was a bit confusing before if compressed data or uncompressed data is handled. Reviewed-by: Peter Hartmann
Diffstat (limited to 'src/network/access')
-rw-r--r--src/network/access/qhttpnetworkconnection.cpp39
-rw-r--r--src/network/access/qhttpnetworkconnection_p.h11
-rw-r--r--src/network/access/qhttpnetworkreply.cpp4
3 files changed, 36 insertions, 18 deletions
diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp
index f0c694d..365ae8b 100644
--- a/src/network/access/qhttpnetworkconnection.cpp
+++ b/src/network/access/qhttpnetworkconnection.cpp
@@ -174,22 +174,29 @@ bool QHttpNetworkConnectionPrivate::isSocketReading(QAbstractSocket *socket) con
}
-void QHttpNetworkConnectionPrivate::appendData(QHttpNetworkReply &reply, const QByteArray &fragment, bool compressed)
+void QHttpNetworkConnectionPrivate::appendUncompressedData(QHttpNetworkReply &reply, const QByteArray &fragment)
{
- QByteArray *ba = (compressed) ? &reply.d_func()->compressedData : &reply.d_func()->responseData;
- ba->append(fragment);
- return;
+ reply.d_func()->responseData.append(fragment);
}
-qint64 QHttpNetworkConnectionPrivate::bytesAvailable(const QHttpNetworkReply &reply, bool compressed) const
+void QHttpNetworkConnectionPrivate::appendCompressedData(QHttpNetworkReply &reply, const QByteArray &fragment)
{
- const QByteArray *ba = (compressed) ? &reply.d_func()->compressedData : &reply.d_func()->responseData;
- return ba->size();
+ reply.d_func()->compressedData.append(fragment);
}
-qint64 QHttpNetworkConnectionPrivate::read(QHttpNetworkReply &reply, QByteArray &data, qint64 maxSize, bool compressed)
+qint64 QHttpNetworkConnectionPrivate::uncompressedBytesAvailable(const QHttpNetworkReply &reply) const
{
- QByteArray *ba = (compressed) ? &reply.d_func()->compressedData : &reply.d_func()->responseData;
+ return reply.d_func()->responseData.size();
+}
+
+qint64 QHttpNetworkConnectionPrivate::compressedBytesAvailable(const QHttpNetworkReply &reply) const
+{
+ return reply.d_func()->compressedData.size();
+}
+
+qint64 QHttpNetworkConnectionPrivate::read(QHttpNetworkReply &reply, QByteArray &data, qint64 maxSize)
+{
+ QByteArray *ba = &reply.d_func()->responseData;
if (maxSize == -1 || maxSize >= ba->size()) {
// read the whole data
data = *ba;
@@ -524,12 +531,14 @@ bool QHttpNetworkConnectionPrivate::expand(QAbstractSocket *socket, QHttpNetwork
Q_ASSERT(socket);
Q_ASSERT(reply);
- qint64 total = bytesAvailable(*reply, true);
+ qint64 total = compressedBytesAvailable(*reply);
if (total >= CHUNK || dataComplete) {
int i = indexOf(socket);
// uncompress the data
QByteArray content, inflated;
- read(*reply, content, -1, true);
+ content = reply->d_func()->compressedData;
+ reply->d_func()->compressedData.clear();
+
int ret = Z_OK;
if (content.size())
ret = reply->d_func()->gunzipBodyPartially(content, inflated);
@@ -537,7 +546,7 @@ bool QHttpNetworkConnectionPrivate::expand(QAbstractSocket *socket, QHttpNetwork
if (ret >= retCheck) {
if (inflated.size()) {
reply->d_func()->totalProgress += inflated.size();
- appendData(*reply, inflated, false);
+ appendUncompressedData(*reply, inflated);
if (shouldEmitSignals(reply)) {
emit reply->readyRead();
// make sure that the reply is valid
@@ -638,7 +647,11 @@ void QHttpNetworkConnectionPrivate::receiveReply(QAbstractSocket *socket, QHttpN
fragment.open(QIODevice::WriteOnly);
bytes = reply->d_func()->readBody(socket, &fragment);
if (bytes) {
- appendData(*reply, fragment.data(), reply->d_func()->autoDecompress);
+ if (reply->d_func()->autoDecompress)
+ appendCompressedData(*reply, fragment.data());
+ else
+ appendUncompressedData(*reply, fragment.data());
+
if (!reply->d_func()->autoDecompress) {
reply->d_func()->totalProgress += fragment.size();
if (shouldEmitSignals(reply)) {
diff --git a/src/network/access/qhttpnetworkconnection_p.h b/src/network/access/qhttpnetworkconnection_p.h
index 64a6faa..bc4d948 100644
--- a/src/network/access/qhttpnetworkconnection_p.h
+++ b/src/network/access/qhttpnetworkconnection_p.h
@@ -254,9 +254,14 @@ public:
bool pendingAuthSignal; // there is an incomplete authentication signal
bool pendingProxyAuthSignal; // there is an incomplete proxy authentication signal
- void appendData(QHttpNetworkReply &reply, const QByteArray &fragment, bool compressed);
- qint64 bytesAvailable(const QHttpNetworkReply &reply, bool compressed = false) const;
- qint64 read(QHttpNetworkReply &reply, QByteArray &data, qint64 maxSize, bool compressed);
+ void appendUncompressedData(QHttpNetworkReply &reply, const QByteArray &fragment);
+ void appendCompressedData(QHttpNetworkReply &reply, const QByteArray &fragment);
+
+ qint64 uncompressedBytesAvailable(const QHttpNetworkReply &reply) const;
+ qint64 compressedBytesAvailable(const QHttpNetworkReply &reply) const;
+
+ qint64 read(QHttpNetworkReply &reply, QByteArray &data, qint64 maxSize);
+
void emitReplyError(QAbstractSocket *socket, QHttpNetworkReply *reply, QNetworkReply::NetworkError errorCode);
bool handleAuthenticateChallenge(QAbstractSocket *socket, QHttpNetworkReply *reply, bool isProxy, bool &resend);
void allDone(QAbstractSocket *socket, QHttpNetworkReply *reply);
diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp
index c4d4a9c..47fb6d1 100644
--- a/src/network/access/qhttpnetworkreply.cpp
+++ b/src/network/access/qhttpnetworkreply.cpp
@@ -162,7 +162,7 @@ qint64 QHttpNetworkReply::bytesAvailable() const
{
Q_D(const QHttpNetworkReply);
if (d->connection)
- return d->connection->d_func()->bytesAvailable(*this);
+ return d->connection->d_func()->uncompressedBytesAvailable(*this);
else
return -1;
}
@@ -172,7 +172,7 @@ QByteArray QHttpNetworkReply::read(qint64 maxSize)
Q_D(QHttpNetworkReply);
QByteArray data;
if (d->connection)
- d->connection->d_func()->read(*this, data, maxSize, false);
+ d->connection->d_func()->read(*this, data, maxSize);
return data;
}