diff options
author | Samuel Rødal <sroedal@trolltech.com> | 2009-05-20 16:43:10 (GMT) |
---|---|---|
committer | Samuel Rødal <sroedal@trolltech.com> | 2009-05-20 16:43:10 (GMT) |
commit | bfde87dcc8d0f363ecf1da59482c15445b00484c (patch) | |
tree | 0d0c01b1611caf91ba900bd2b67a8806590254cc /src/network | |
parent | 27fadaa7eb2d58b47e7f0f508e3402e7a8de3894 (diff) | |
parent | f9d26f0bebd5bcc32d15c4a627251c44cf78389e (diff) | |
download | Qt-bfde87dcc8d0f363ecf1da59482c15445b00484c.zip Qt-bfde87dcc8d0f363ecf1da59482c15445b00484c.tar.gz Qt-bfde87dcc8d0f363ecf1da59482c15445b00484c.tar.bz2 |
Merge commit 'qt/master'
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/access/qhttp.cpp | 4 | ||||
-rw-r--r-- | src/network/access/qhttpnetworkconnection.cpp | 47 | ||||
-rw-r--r-- | src/network/access/qnetworkaccesshttpbackend.cpp | 42 | ||||
-rw-r--r-- | src/network/access/qnetworkdiskcache.cpp | 6 | ||||
-rw-r--r-- | src/network/kernel/qnetworkinterface.cpp | 2 | ||||
-rw-r--r-- | src/network/socket/qabstractsocket.cpp | 2 |
6 files changed, 65 insertions, 38 deletions
diff --git a/src/network/access/qhttp.cpp b/src/network/access/qhttp.cpp index 96ccc91..c761a02 100644 --- a/src/network/access/qhttp.cpp +++ b/src/network/access/qhttp.cpp @@ -950,7 +950,7 @@ void QHttpHeader::setContentLength(int len) } /*! - Returns true if the header has an entry for the the special HTTP + Returns true if the header has an entry for the special HTTP header field \c content-type; otherwise returns false. \sa contentType() setContentType() @@ -1446,7 +1446,7 @@ QString QHttpRequestHeader::toString() const that indicates if the request finished with an error. To make an HTTP request you must set up suitable HTTP headers. The - following example demonstrates, how to request the main HTML page + following example demonstrates how to request the main HTML page from the Trolltech home page (i.e., the URL \c http://qtsoftware.com/index.html): diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index d4bf008..43fbb16 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -703,27 +703,37 @@ void QHttpNetworkConnectionPrivate::handleStatus(QAbstractSocket *socket, QHttpN switch (statusCode) { case 401: case 407: - handleAuthenticateChallenge(socket, reply, (statusCode == 407), resend); - if (resend) { - int i = indexOf(socket); - - QNonContiguousByteDevice* uploadByteDevice = channels[i].request.uploadByteDevice(); - if (uploadByteDevice) { - if (uploadByteDevice->reset()) { - channels[i].written = 0; - } else { - emitReplyError(socket, reply, QNetworkReply::ContentReSendError); - break; + if (handleAuthenticateChallenge(socket, reply, (statusCode == 407), resend)) { + if (resend) { + int i = indexOf(socket); + + QNonContiguousByteDevice* uploadByteDevice = channels[i].request.uploadByteDevice(); + if (uploadByteDevice) { + if (uploadByteDevice->reset()) { + channels[i].written = 0; + } else { + emitReplyError(socket, reply, QNetworkReply::ContentReSendError); + break; + } } - } - - eraseData(reply); - // also use async _q_startNextRequest so we dont break with closed - // proxy or server connections.. - channels[i].resendCurrent = true; - QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); + eraseData(reply); + // also use async _q_startNextRequest so we dont break with closed + // proxy or server connections.. + channels[i].resendCurrent = true; + QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); + } + } else { + int i = indexOf(socket); + emit channels[i].reply->headerChanged(); + emit channels[i].reply->readyRead(); + QNetworkReply::NetworkError errorCode = (statusCode == 407) + ? QNetworkReply::ProxyAuthenticationRequiredError + : QNetworkReply::AuthenticationRequiredError; + reply->d_func()->errorString = errorDetail(errorCode, socket); + emit q->error(errorCode, reply->d_func()->errorString); + emit channels[i].reply->finished(); } break; default: @@ -826,7 +836,6 @@ bool QHttpNetworkConnectionPrivate::handleAuthenticateChallenge(QAbstractSocket // authentication is cancelled, send the current contents to the user. emit channels[i].reply->headerChanged(); emit channels[i].reply->readyRead(); - emit channels[i].reply->finished(); QNetworkReply::NetworkError errorCode = isProxy ? QNetworkReply::ProxyAuthenticationRequiredError diff --git a/src/network/access/qnetworkaccesshttpbackend.cpp b/src/network/access/qnetworkaccesshttpbackend.cpp index 7d0438e..bd364cb 100644 --- a/src/network/access/qnetworkaccesshttpbackend.cpp +++ b/src/network/access/qnetworkaccesshttpbackend.cpp @@ -973,21 +973,39 @@ QNetworkCacheMetaData QNetworkAccessHttpBackend::fetchCacheMetaData(const QNetwo if (it != cacheHeaders.rawHeaders.constEnd()) metaData.setLastModified(QNetworkHeadersPrivate::fromHttpDate(it->second)); - bool canDiskCache = true; // Everything defaults to being cacheable on disk - - // 14.32 - // HTTP/1.1 caches SHOULD treat "Pragma: no-cache" as if the client - // had sent "Cache-Control: no-cache". - it = cacheHeaders.findRawHeader("pragma"); - if (it != cacheHeaders.rawHeaders.constEnd() - && it->second == "no-cache") - canDiskCache = false; + bool canDiskCache; + // only cache GET replies by default, all other replies (POST, PUT, DELETE) + // are not cacheable by default (according to RFC 2616 section 9) + if (httpReply->request().operation() == QHttpNetworkRequest::Get) { + + canDiskCache = true; + // 14.32 + // HTTP/1.1 caches SHOULD treat "Pragma: no-cache" as if the client + // had sent "Cache-Control: no-cache". + it = cacheHeaders.findRawHeader("pragma"); + if (it != cacheHeaders.rawHeaders.constEnd() + && it->second == "no-cache") + canDiskCache = false; + + // HTTP/1.1. Check the Cache-Control header + if (cacheControl.contains("no-cache")) + canDiskCache = false; + else if (cacheControl.contains("no-store")) + canDiskCache = false; + + // responses to POST might be cacheable + } else if (httpReply->request().operation() == QHttpNetworkRequest::Post) { - // HTTP/1.1. Check the Cache-Control header - if (cacheControl.contains("no-cache")) canDiskCache = false; - else if (cacheControl.contains("no-store")) + // some pages contain "expires:" and "cache-control: no-cache" field, + // so we only might cache POST requests if we get "cache-control: max-age ..." + if (cacheControl.contains("max-age")) + canDiskCache = true; + + // responses to PUT and DELETE are not cacheable + } else { canDiskCache = false; + } metaData.setSaveToDisk(canDiskCache); int statusCode = httpReply->statusCode(); diff --git a/src/network/access/qnetworkdiskcache.cpp b/src/network/access/qnetworkdiskcache.cpp index d42370d..0ca6b13 100644 --- a/src/network/access/qnetworkdiskcache.cpp +++ b/src/network/access/qnetworkdiskcache.cpp @@ -496,21 +496,21 @@ qint64 QNetworkDiskCache::expire() QDir::Filters filters = QDir::AllDirs | QDir:: Files | QDir::NoDotAndDotDot; QDirIterator it(cacheDirectory(), filters, QDirIterator::Subdirectories); - QMap<QDateTime, QString> cacheItems; + QMultiMap<QDateTime, QString> cacheItems; qint64 totalSize = 0; while (it.hasNext()) { QString path = it.next(); QFileInfo info = it.fileInfo(); QString fileName = info.fileName(); if (fileName.endsWith(CACHE_POSTFIX) && fileName.startsWith(CACHE_PREFIX)) { - cacheItems[info.created()] = path; + cacheItems.insert(info.created(), path); totalSize += info.size(); } } int removedFiles = 0; qint64 goal = (maximumCacheSize() * 9) / 10; - QMap<QDateTime, QString>::const_iterator i = cacheItems.constBegin(); + QMultiMap<QDateTime, QString>::const_iterator i = cacheItems.constBegin(); while (i != cacheItems.constEnd()) { if (totalSize < goal) break; diff --git a/src/network/kernel/qnetworkinterface.cpp b/src/network/kernel/qnetworkinterface.cpp index 670745b..960999e 100644 --- a/src/network/kernel/qnetworkinterface.cpp +++ b/src/network/kernel/qnetworkinterface.cpp @@ -397,7 +397,7 @@ QNetworkInterface::~QNetworkInterface() } /*! - Creates a copy of the the QNetworkInterface object contained in \a + Creates a copy of the QNetworkInterface object contained in \a other. */ QNetworkInterface::QNetworkInterface(const QNetworkInterface &other) diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp index f9750f2..336a7e7 100644 --- a/src/network/socket/qabstractsocket.cpp +++ b/src/network/socket/qabstractsocket.cpp @@ -1127,7 +1127,7 @@ bool QAbstractSocketPrivate::readFromSocket() /*! \internal - Sets up the the internal state after the connection has succeeded. + Sets up the internal state after the connection has succeeded. */ void QAbstractSocketPrivate::fetchConnectionParameters() { |