| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/access/qnetworkaccesscachebackend.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
| 5 | ** | - | ||||||||||||
| 6 | ** This file is part of the QtNetwork module of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
| 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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
| 25 | ** | - | ||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
| 29 | ** | - | ||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 31 | ** | - | ||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||
| 33 | - | |||||||||||||
| 34 | //#define QNETWORKACCESSCACHEBACKEND_DEBUG | - | ||||||||||||
| 35 | - | |||||||||||||
| 36 | #include "qnetworkaccesscachebackend_p.h" | - | ||||||||||||
| 37 | #include "qabstractnetworkcache.h" | - | ||||||||||||
| 38 | #include "qfileinfo.h" | - | ||||||||||||
| 39 | #include "qurlinfo_p.h" | - | ||||||||||||
| 40 | #include "qdir.h" | - | ||||||||||||
| 41 | #include "qcoreapplication.h" | - | ||||||||||||
| 42 | - | |||||||||||||
| 43 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 44 | - | |||||||||||||
| 45 | QNetworkAccessCacheBackend::QNetworkAccessCacheBackend() | - | ||||||||||||
| 46 | : QNetworkAccessBackend() | - | ||||||||||||
| 47 | { | - | ||||||||||||
| 48 | } executed 14 times by 3 tests: end of blockExecuted by:
| 14 | ||||||||||||
| 49 | - | |||||||||||||
| 50 | QNetworkAccessCacheBackend::~QNetworkAccessCacheBackend() | - | ||||||||||||
| 51 | { | - | ||||||||||||
| 52 | } | - | ||||||||||||
| 53 | - | |||||||||||||
| 54 | void QNetworkAccessCacheBackend::open() | - | ||||||||||||
| 55 | { | - | ||||||||||||
| 56 | if (operation() != QNetworkAccessManager::GetOperation || !sendCacheContents()) {
| 0-13 | ||||||||||||
| 57 | QString msg = QCoreApplication::translate("QNetworkAccessCacheBackend", "Error opening %1") | - | ||||||||||||
| 58 | .arg(this->url().toString()); | - | ||||||||||||
| 59 | error(QNetworkReply::ContentNotFoundError, msg); | - | ||||||||||||
| 60 | } else { executed 4 times by 2 tests: end of blockExecuted by:
| 4 | ||||||||||||
| 61 | setAttribute(QNetworkRequest::SourceIsFromCacheAttribute, true); | - | ||||||||||||
| 62 | } executed 9 times by 2 tests: end of blockExecuted by:
| 9 | ||||||||||||
| 63 | finished(); | - | ||||||||||||
| 64 | } executed 13 times by 2 tests: end of blockExecuted by:
| 13 | ||||||||||||
| 65 | - | |||||||||||||
| 66 | bool QNetworkAccessCacheBackend::sendCacheContents() | - | ||||||||||||
| 67 | { | - | ||||||||||||
| 68 | setCachingEnabled(false); | - | ||||||||||||
| 69 | QAbstractNetworkCache *nc = networkCache(); | - | ||||||||||||
| 70 | if (!nc)
| 0-13 | ||||||||||||
| 71 | return false; never executed: return false; | 0 | ||||||||||||
| 72 | - | |||||||||||||
| 73 | QNetworkCacheMetaData item = nc->metaData(url()); | - | ||||||||||||
| 74 | if (!item.isValid())
| 1-12 | ||||||||||||
| 75 | return false; executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||
| 76 | - | |||||||||||||
| 77 | QNetworkCacheMetaData::AttributesMap attributes = item.attributes(); | - | ||||||||||||
| 78 | setAttribute(QNetworkRequest::HttpStatusCodeAttribute, attributes.value(QNetworkRequest::HttpStatusCodeAttribute)); | - | ||||||||||||
| 79 | setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, attributes.value(QNetworkRequest::HttpReasonPhraseAttribute)); | - | ||||||||||||
| 80 | - | |||||||||||||
| 81 | // set the raw headers | - | ||||||||||||
| 82 | QNetworkCacheMetaData::RawHeaderList rawHeaders = item.rawHeaders(); | - | ||||||||||||
| 83 | QNetworkCacheMetaData::RawHeaderList::ConstIterator it = rawHeaders.constBegin(), | - | ||||||||||||
| 84 | end = rawHeaders.constEnd(); | - | ||||||||||||
| 85 | for ( ; it != end; ++it) {
| 9-39 | ||||||||||||
| 86 | if (it->first.toLower() == "cache-control" &&
| 5-34 | ||||||||||||
| 87 | it->second.toLower().contains("must-revalidate")) {
| 2-3 | ||||||||||||
| 88 | return false; executed 3 times by 2 tests: return false;Executed by:
| 3 | ||||||||||||
| 89 | } | - | ||||||||||||
| 90 | setRawHeader(it->first, it->second); | - | ||||||||||||
| 91 | } executed 36 times by 2 tests: end of blockExecuted by:
| 36 | ||||||||||||
| 92 | - | |||||||||||||
| 93 | // handle a possible redirect | - | ||||||||||||
| 94 | QVariant redirectionTarget = attributes.value(QNetworkRequest::RedirectionTargetAttribute); | - | ||||||||||||
| 95 | if (redirectionTarget.isValid()) {
| 0-9 | ||||||||||||
| 96 | setAttribute(QNetworkRequest::RedirectionTargetAttribute, redirectionTarget); | - | ||||||||||||
| 97 | redirectionRequested(redirectionTarget.toUrl()); | - | ||||||||||||
| 98 | } never executed: end of block | 0 | ||||||||||||
| 99 | - | |||||||||||||
| 100 | // signal we're open | - | ||||||||||||
| 101 | metaDataChanged(); | - | ||||||||||||
| 102 | - | |||||||||||||
| 103 | if (operation() == QNetworkAccessManager::GetOperation) {
| 0-9 | ||||||||||||
| 104 | QIODevice *contents = nc->data(url()); | - | ||||||||||||
| 105 | if (!contents)
| 0-9 | ||||||||||||
| 106 | return false; never executed: return false; | 0 | ||||||||||||
| 107 | contents->setParent(this); | - | ||||||||||||
| 108 | writeDownstreamData(contents); | - | ||||||||||||
| 109 | } executed 9 times by 2 tests: end of blockExecuted by:
| 9 | ||||||||||||
| 110 | - | |||||||||||||
| 111 | #if defined(QNETWORKACCESSCACHEBACKEND_DEBUG) | - | ||||||||||||
| 112 | qDebug() << "Successfully sent cache:" << url(); | - | ||||||||||||
| 113 | #endif | - | ||||||||||||
| 114 | return true; executed 9 times by 2 tests: return true;Executed by:
| 9 | ||||||||||||
| 115 | } | - | ||||||||||||
| 116 | - | |||||||||||||
| 117 | void QNetworkAccessCacheBackend::closeDownstreamChannel() | - | ||||||||||||
| 118 | { | - | ||||||||||||
| 119 | } | - | ||||||||||||
| 120 | - | |||||||||||||
| 121 | void QNetworkAccessCacheBackend::closeUpstreamChannel() | - | ||||||||||||
| 122 | { | - | ||||||||||||
| 123 | Q_ASSERT_X(false, Q_FUNC_INFO, "This function show not have been called!"); | - | ||||||||||||
| 124 | } never executed: end of block | 0 | ||||||||||||
| 125 | - | |||||||||||||
| 126 | void QNetworkAccessCacheBackend::upstreamReadyRead() | - | ||||||||||||
| 127 | { | - | ||||||||||||
| 128 | Q_ASSERT_X(false, Q_FUNC_INFO, "This function show not have been called!"); | - | ||||||||||||
| 129 | } never executed: end of block | 0 | ||||||||||||
| 130 | - | |||||||||||||
| 131 | void QNetworkAccessCacheBackend::downstreamReadyWrite() | - | ||||||||||||
| 132 | { | - | ||||||||||||
| 133 | Q_ASSERT_X(false, Q_FUNC_INFO, "This function show not have been called!"); | - | ||||||||||||
| 134 | } never executed: end of block | 0 | ||||||||||||
| 135 | - | |||||||||||||
| 136 | QT_END_NAMESPACE | - | ||||||||||||
| 137 | - | |||||||||||||
| Source code | Switch to Preprocessed file |